httpx

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP_METHOD_GET     = "GET"     //请求指定的页面信息,并返回实体主体。
	HTTP_METHOD_POST    = "POST"    //向指定资源提交数据进行处理请求(例如提交表单或者上传文件)。数据被包含在请求体中。POST 请求可能会导致新的资源的建立和/或已有资源的修改。
	HTTP_METHOD_PUT     = "PUT"     //从客户端向服务器传送的数据取代指定的文档的内容。
	HTTP_METHOD_CONNECT = "CONNECT" //HTTP/1.1 协议中预留给能够将连接改为管道方式的代理服务器
	HTTP_METHOD_OPTIONS = "OPTIONS" //允许客户端查看服务器的性能。
	HTTP_METHOD_DELETE  = "DELETE"  //请求服务器删除指定的页面内容。
	HTTP_METHOD_TRACE   = "TRACE"   //回显服务器收到的请求,主要用于测试或诊断。
	HTTP_METHOD_PATCH   = "PATCH"   //是对PUT方法的补充,用来对已知资源进行局部更新。
	HTTP_METHOD_HEAD    = "HEAD"    //类似于GET请求,只不过返回的响应中没有具体的内容,用于获取报头
)
View Source
const (
	HEADER_KEY_CONTENT_TYPE  = "Content-Type"
	HEADER_KEY_AUTHORIZATION = "Authorization"
)
View Source
const (
	CONTENT_TYPE_NAME_TEXT_PLAIN             = "text/plain"                        //content-type (raw)
	CONTENT_TYPE_NAME_MULTIPART_FORM_DATA    = "multipart/form-data"               //content-type (form-data)
	CONTENT_TYPE_NAME_X_WWW_FORM_URL_ENCODED = "application/x-www-form-urlencoded" //content-type (urlencoded)
	CONTENT_TYPE_NAME_APPLICATION_JSON       = "application/json"                  //content-type (json)
	CONTENT_TYPE_NAME_TEXT_HTML              = "text/html"                         //content-type (html)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient(timeout int) *Client

新建一个HTTP客户端对象 timeout 连接超时秒数

func NewHttpsClient

func NewHttpsClient(timeout int, cer interface{}) *Client

新建一个HTTPS客户端对象 timeout 连接超时秒数 cer PEM证书文件路径(string)或二进制数据([]byte)

func (*Client) Delete

func (c *Client) Delete(strUrl string) (response *Response, err error)

发起HTTP DELETE请求(send a http request by DELETE method)

func (*Client) Get

func (c *Client) Get(strUrl string, values UrlValues) (response *Response, err error)

发起HTTP GET请求(send a http request by GET method)

func (*Client) Header

func (c *Client) Header() *Header

func (*Client) Patch

func (c *Client) Patch(strUrl string) (response *Response, err error)

发起HTTP PATCH请求(send a http request by PATCH method)

func (*Client) Post

func (c *Client) Post(strUrl string, data interface{}) (response *Response, err error)

发起HTTP POST请求(send a http request by POST method with content-type multipart/form-data or application/x-www-form-urlencoded) data 类型 string、[]byte、UrlValues或结构体[对象或引用]

func (*Client) PostUrlEncoded

func (c *Client) PostUrlEncoded(strUrl string, values UrlValues) (response *Response, err error)

发起HTTP POST请求(send a http request by POST method with application/x-www-form-urlencoded)

func (*Client) Put

func (c *Client) Put(strUrl string) (response *Response, err error)

发起HTTP PUT请求(send a http request by PUT method)

func (*Client) Trace

func (c *Client) Trace(strUrl string) (response *Response, err error)

发起HTTP TRACE请求(send a http request by TRACE method)

type Header struct {
	// contains filtered or unexported fields
}

func (*Header) Delete

func (h *Header) Delete(strKey string)

删除http请求头部参数

func (*Header) Get

func (h *Header) Get(strKey string) (strValue string)

获取http请求头部strKey对应的值

func (*Header) RemoveAll

func (h *Header) RemoveAll()

删除http请求所有头部参数

func (*Header) Set

func (h *Header) Set(strKey, strValue string) *Header

设置http请求头部内容类型(自定义key-value)

func (*Header) SetApplicationJson

func (h *Header) SetApplicationJson() *Header

设置http请求头部内容类型(Content-Type=application/json)

func (*Header) SetAuthorization

func (h *Header) SetAuthorization(strValue string) *Header

设置http请求头部key="Authorization" value=strValue

func (*Header) SetMultipartFormData

func (h *Header) SetMultipartFormData() *Header

设置http请求头部内容类型(Content-Type=multipart/form-data)

func (*Header) SetTextHtml

func (h *Header) SetTextHtml() *Header

设置http请求头部内容类型(Content-Type=text/html)

func (*Header) SetTextPlain

func (h *Header) SetTextPlain() *Header

设置http请求头部内容类型(Content-Type=text/plain)

func (*Header) SetUrlEncoded

func (h *Header) SetUrlEncoded() *Header

设置http请求头部内容类型(Content-Type=application/x-www-form-urlencoded)

type HttpServer

type HttpServer struct {
}

func NewServer

func NewServer() *HttpServer

type Response

type Response struct {
	StatusCode  int
	ContentType string
	Body        string
}

type UrlValues

type UrlValues map[string]interface{} //POST提交表单参数

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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