Documentation
¶
Index ¶
- Constants
- Variables
- func CheckRedirect(r *http.Request, via []*http.Request) error
- func Delete(url string) (string, error)
- func DeleteEx(url string, option *HttpOption) (string, error)
- func DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func DoEx(url, method string, option *HttpOption) (string, error)
- func Get(url string) (string, error)
- func GetBody(r *http.Response) (string, error)
- func GetCookies(r *http.Response) ([]*http.Cookie, error)
- func GetEx(url string, option *HttpOption) (string, error)
- func GetQueryString(m map[string]string) string
- func GetRawParameter(r *http.Request) (string, error)
- func HTMLDecode(html string) string
- func HttpsBasicAuthorization(username, password string) (string, error)
- func NewHTTPRequest(r *Request, body io.Reader) (*http.Request, error)
- func NewRawRequest(method, urlStr string, setOpaque bool, body io.Reader) (*http.Request, error)
- func Post(url, parameter string, contentType ContentType) (string, error)
- func PostEx(url string, option *HttpOption) (string, error)
- func PrintCookies(cookies []*http.Cookie, page string)
- func Put(url, parameter string, contentType ContentType) (string, error)
- func PutEx(url string, option *HttpOption) (string, error)
- func URLEncode(path string) string
- type ContentType
- type HttpOption
- type Request
Constants ¶
View Source
const ( HttpGet = "GET" HttpPost = "POST" HttpPut = "PUT" HttpDelete = "DELETE" DefaultTimeout = time.Duration(30) * time.Second )
Variables ¶
View Source
var ( //DialTimeoutSeconds 超时秒数 DialTimeoutSeconds time.Duration = 30 )
Functions ¶
func CheckRedirect ¶
CheckRedirect 检测重定向
func DeleteEx ¶
func DeleteEx(url string, option *HttpOption) (string, error)
DeleteEx DELETE方式请求URL
func DialContext ¶
DialContext 处理连接超时
func GetRawParameter ¶
GetRawParameter 获取原始请求参数
func HttpsBasicAuthorization ¶
HttpsBasicAuthorization 创建HTTPS认证字符串
func NewHTTPRequest ¶
NewHTTPRequest 创建新的HTTP请求(重写http.NewRequest方法,因为该方法会对URL进行转码)
func NewRawRequest ¶
NewRawRequest 创建新的HTTP请求(重写http.NewRequest方法,因为该方法会对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 //请在此之前添加新的定义 )
type HttpOption ¶
type HttpOption struct {
Parameter string //URL参数或表单参数
ContentType ContentType //参数类型
Timeout time.Duration //超时
IgnoreStatusCode bool //是否忽略HTTP状态
}
HttpOption HTTP选项类
func EnsureHttpOption ¶
func EnsureHttpOption(option *HttpOption) *HttpOption
EnsureHttpOption 确保HttpOption有效
func NewHttpOption ¶
func NewHttpOption(parameter string, contentType ContentType) *HttpOption
NewHttpOption 获取新的HttpOption实例
func NewHttpOptionEx ¶
func NewHttpOptionEx(parameter string, contentType ContentType, timeout time.Duration, ignoreStatusCode bool) *HttpOption
NewHttpOptionEx 获取新的HttpOption实例
func (*HttpOption) GetParameterReader ¶
func (option *HttpOption) GetParameterReader() io.Reader
GetParameterReader 获取参数读取器实例
func (*HttpOption) SetJsonParameter ¶
func (option *HttpOption) SetJsonParameter(data interface{}) error
SetJsonParameter 设置JSON格式参数
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请求类
Click to show internal directories.
Click to hide internal directories.