httpx

package
v0.0.0-...-4f7920e Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHeader

func AddHeader(h *http.Header, name, value string) error

AddHeader 添加一个头

func CopyHTTPRequest

func CopyHTTPRequest(r *http.Request, body io.ReadCloser) *http.Request

CopyHTTPRequest 用于复制新的HTTP Request

CopyHTTPRequest(req, ioutil.NopCloser(&bytes.Buffer{}))

func DelHeader

func DelHeader(h *http.Header, name string) error

DelHeader 删除一个header 项

func FromJSON

func FromJSON(req interface{}, r *http.Request) (body []byte, err error)

FromJSON 将body 进行 json解码

func GetCookieValue

func GetCookieValue(cookies, name string) (ret string)

GetCookieValue 获取指定名称的cookie

func GetRemoteAddr

func GetRemoteAddr(r *http.Request) string

func HeaderToArray

func HeaderToArray(header http.Header) (res []string)

func ToJSON

func ToJSON(i interface{}, w io.Writer) error

example:

buf := &bytes.Buffer{}
ToJSON(x, buf)
buf.Bytes()

ToJSON serializes the given interface into a string based JSON format

Types

type Client

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

func NewClient

func NewClient() *Client

func (*Client) GetByte

func (c *Client) GetByte(ctx context.Context, method, url string, body io.Reader,
	opts ...HeaderOpion) (*Response, error)

GetByte 相当于http.get()

func (*Client) GetClient

func (c *Client) GetClient() *http.Client

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, url string, body io.Reader,
	opts ...HeaderOpion) (*http.Response, error)

method 参数: http.MethodGet http.MethodPost 等, 如为非标准的访问请求会被报400

func (*Client) WithClient

func (c *Client) WithClient(cl *http.Client)

type HeaderOpion

type HeaderOpion func(*http.Request)

type Response

type Response struct {
	Body          []byte
	StatusCode    int
	RedirectedURL string
	Header        []string
}

Response HTTP请求返回的结构体

Jump to

Keyboard shortcuts

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