requests

package module
v0.0.0-...-8f4191e Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: MIT Imports: 10 Imported by: 0

README

requests

go http request client

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContentTypeKey = "Content-Type"

Functions

func LoadCerts

func LoadCerts(certFile, keyFile string) ([]tls.Certificate, error)

Load certificate files with PEM format

func NewTransport

func NewTransport(targetHostPem []byte, myCerts []tls.Certificate, skipVerify bool) *http.Transport

NewTransport new http2 transport. For http client, please skip targetHostPem,myCert.

Types

type Client

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

func NewClient

func NewClient(options Options) *Client

func (*Client) AppendCookie

func (s *Client) AppendCookie(cookie *http.Cookie) *Client

func (*Client) Client

func (s *Client) Client() *http.Client

func (*Client) Close

func (s *Client) Close() error

func (*Client) Cookies

func (s *Client) Cookies() []*http.Cookie

func (*Client) Get

func (s *Client) Get(uri string, query, header map[string]string) (*Response, error)

func (*Client) Headers

func (s *Client) Headers() map[string]string

func (*Client) Options

func (s *Client) Options() Options

func (*Client) PostForm

func (s *Client) PostForm(uri string, query, form map[string]string, files []UploadFile) (*Response, error)

func (*Client) PostJSON

func (s *Client) PostJSON(uri string, query map[string]string, data interface{}) (*Response, error)

func (*Client) Request

func (s *Client) Request(method, url string, urlQuery map[string]string, body io.Reader) (*Response, error)

func (*Client) SetCookies

func (s *Client) SetCookies(cookies []*http.Cookie) *Client

func (*Client) SetHeader

func (s *Client) SetHeader(name, value string) *Client

func (*Client) SetHeaders

func (s *Client) SetHeaders(headers map[string]string) *Client

func (*Client) SetTransport

func (s *Client) SetTransport(transport http.RoundTripper) *Client

func (*Client) Transport

func (s *Client) Transport() http.RoundTripper

type Closeable

type Closeable interface {
	Close() error
}

type Options

type Options struct {
	TargetHostPem []byte
	MyCerts       []tls.Certificate
	SkipVerify    bool
	Headers       map[string]string
	Cookies       []*http.Cookie
	Timeout       time.Duration
	NoBody        bool // if true, not read response body
}

type Response

type Response struct {
	*http.Response
	// contains filtered or unexported fields
}

func (*Response) Bytes

func (s *Response) Bytes() []byte

func (*Response) Json

func (s *Response) Json(v interface{}) error

func (*Response) Text

func (s *Response) Text() string

type UploadFile

type UploadFile struct {
	Filename string
	Field    string
	Content  io.Reader
}

Jump to

Keyboard shortcuts

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