http

package
v0.0.0-...-59c608d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2023 License: GPL-3.0 Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 30 * time.Second
)

Variables

View Source
var (
	//DialTimeoutSeconds 超时秒数
	DialTimeoutSeconds time.Duration = 30
)

Functions

func CheckRedirect

func CheckRedirect(r *http.Request, via []*http.Request) error

CheckRedirect 检测重定向

func DialContext

func DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext 处理连接超时

func Get

func Get(url string) (string, error)

Get GET方式请求URL(默认30秒超时)

func GetBody

func GetBody(r *http.Response) (string, error)

GetBody 获取HTTP响应体

func GetCookies

func GetCookies(r *http.Response) ([]*http.Cookie, error)

GetCookies 获取Cookies

func GetEx

func GetEx(url, parameter string, timeout time.Duration) (string, error)

Get GET方式请求URL(可设置超时)

func GetQueryString

func GetQueryString(m map[string]string) string

GetQueryString 获取查询字符串

func GetRawParameter

func GetRawParameter(r *http.Request) (string, error)

GetRawParameter 获取原始请求参数

func HTMLDecode

func HTMLDecode(html string) string

HTMLDecode HTML解码

func HttpsBasicAuthorization

func HttpsBasicAuthorization(username, password string) (string, error)

HttpsBasicAuthorization 创建HTTPS认证字符串

func NewHTTPRequest

func NewHTTPRequest(r *Request, body io.Reader) (*http.Request, error)

NewHTTPRequest 创建新的HTTP请求(重写http.NewRequest方法,因为该方法会对URL进行转码)

func NewRawRequest

func NewRawRequest(method, urlStr string, setOpaque bool, body io.Reader) (*http.Request, error)

NewRawRequest 创建新的HTTP请求(重写http.NewRequest方法,因为该方法会对URL进行转码)

func Post

func Post(url, parameter string, timeout time.Duration, contentType ContentType) (string, error)

Post POST方式请求URL

func PostEx

func PostEx(url string, reader io.Reader, timeout time.Duration, contentType ContentType) (string, error)

PostEx POST方式请求URL

func PrintCookies

func PrintCookies(cookies []*http.Cookie, page string)

PrintCookies 打印Cookies

func URLEncode

func URLEncode(path string) string

URLEncode URL编码

Types

type ContentType

type ContentType int

ContentType ContentType枚举定义

const (
	//TextPlain 普通文本
	TextPlain ContentType = iota

	//TextHTML Html文本
	TextHTML

	//TextXML Xml文本
	TextXML

	//ApplicationJSON Json内容
	ApplicationJSON

	// ApplicationXML Xml内容
	ApplicationXML

	//ApplicationXWwwFormURLEncoded URL编码后的表单内容
	ApplicationXWwwFormURLEncoded

	//MultipartFormData 多分部表单数据
	MultipartFormData

	//MultipartMixed 多分部混合数据
	MultipartMixed

	//ImageGif GIF图片
	ImageGif

	//ImageJpeg JPEG图片
	ImageJpeg

	//UnknownType 未知类型
	UnknownType //请在此之前添加新的定义
)

func (ContentType) String

func (ct ContentType) String() string

获取ContentType的字符串值

func (ContentType) Value

func (ct ContentType) Value() int

Value 获取ContentType的整数值

type Request

type Request struct {
	URL                string            //Url 要请求的ULR地址
	Method             string            //Method 请求类型:GET,POST,默认:GET
	PostData           map[string]string //PostData 请求要发送的数据
	PostString         string            // 请求要发送的字符串
	SetOpaque          bool              // 是否设置URL不转码
	ContentEncoding    string            // 提交数据:PostData_Text 的编码,默认值:UTF8
	Accept             string            // Accept: application/json
	UserName           string            // 用户账号
	Password           string            // 用户密码
	AcceptEncoding     string            // 声明浏览器支持的编码类型:gzip,deflate,identity 中的一种或多种,逗号分开。默认:gzip,deflate
	AcceptLanguage     string            // 支持的语言
	ContentType        string            // 内容类型,默认值: "application/x-www-form-urlencoded; charset=UTF-8";
	TimeoutSeconds     int               // 请求超时时间(秒为单位),默认:30秒
	WebProxy           string            // 代理服务器IP地址:222.222.222.222:80
	BypassProxyOnLocal bool              // 如果对本地地址不使用代理服务器,则为 true;否则为 false。默认值为 false。
	UserAgent          string            // 浏览器信息,默认:	Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
	Referer            string            // 引用页 默认值string.Empty。
	Origin             string            // 来源
	Headers            map[string]string // 头信息
	ErrorInfo          string            // 错误信息
	AllowAutoRedirect  bool              // 是否根据301跳转
	Host               string            // 服务器主机
	Cookies            []*http.Cookie    // Cookies
	CookieJar          *cookiejar.Jar    // CookiesJar
}

Request HTTP请求类

func (*Request) Do

func (r *Request) Do() (string, error)

Do 发送请求

func (*Request) DoEx

func (r *Request) DoEx() (string, []*http.Cookie, error)

DoEx 发送请求

func (*Request) Get

func (r *Request) Get() (string, error)

Get 发送GET请求

func (*Request) GetEx

func (r *Request) GetEx() (string, []*http.Cookie, error)

GetEx 发送GET请求

func (*Request) Post

func (r *Request) Post() (string, error)

Post 发送POST请求

func (*Request) PostEx

func (r *Request) PostEx() (string, []*http.Cookie, error)

PostEx 发送POST请求

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL