requests

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PostFile

func PostFile(url string, params map[string]string, nameField string, fileName string, file io.Reader) ([]byte, error)

上传文件 url 请求地址 params post form里数据 nameField 请求地址上传文件对应field fileName 文件名 file 文件

Types

type HttpSession

type HttpSession struct {
	Cookies   map[string]*http.Cookie
	Transport *http.Transport
}

func (*HttpSession) GetCookieString

func (session *HttpSession) GetCookieString() string

func (*HttpSession) SetCookie

func (session *HttpSession) SetCookie(cookies []*http.Cookie)

type Request

type Request struct {
	HttpRequest   *http.Request
	Method        string
	Url           string
	Body          string
	Params        map[string]string
	Headers       map[string]string
	AllowRedirect bool
	Timeout       int
}

type RequestBuilder

type RequestBuilder struct {
	HttpSession *HttpSession
	Request     *Request
}

func Get

func Get(url string) *RequestBuilder

func NewHttpSession

func NewHttpSession() *RequestBuilder

func NewRequest

func NewRequest() *RequestBuilder

func Post

func Post(url string) *RequestBuilder

func (*RequestBuilder) AllowRedirect

func (rb *RequestBuilder) AllowRedirect(allow bool) *RequestBuilder

func (*RequestBuilder) Body

func (rb *RequestBuilder) Body(body string) *RequestBuilder

func (*RequestBuilder) Get

func (rb *RequestBuilder) Get(url string) *RequestBuilder

func (*RequestBuilder) GetRequest

func (rb *RequestBuilder) GetRequest() *Request

func (*RequestBuilder) Header

func (rb *RequestBuilder) Header(key string, value string) *RequestBuilder

func (*RequestBuilder) Headers

func (rb *RequestBuilder) Headers(headers map[string]string) *RequestBuilder

func (*RequestBuilder) Method

func (rb *RequestBuilder) Method(method string) *RequestBuilder

func (*RequestBuilder) Param

func (rb *RequestBuilder) Param(key string, value string) *RequestBuilder

func (*RequestBuilder) ParamString

func (rb *RequestBuilder) ParamString(params string) *RequestBuilder

func (*RequestBuilder) Params

func (rb *RequestBuilder) Params(params map[string]string) *RequestBuilder

func (*RequestBuilder) Post

func (rb *RequestBuilder) Post(url string) *RequestBuilder

func (*RequestBuilder) Send

func (rb *RequestBuilder) Send() *ResponseParser

func (*RequestBuilder) SendWithRequest

func (rb *RequestBuilder) SendWithRequest(req *Request) *ResponseParser

func (*RequestBuilder) Timeout

func (rb *RequestBuilder) Timeout(timeout int) *RequestBuilder

func (*RequestBuilder) Url

func (rb *RequestBuilder) Url(url string) *RequestBuilder

func (*RequestBuilder) WithHttpRequest

func (rb *RequestBuilder) WithHttpRequest(request *http.Request) *RequestBuilder

type Response

type Response struct {
	HttpResponse   *http.Response
	ResponseWriter http.ResponseWriter
	Body           string
	Headers        map[string]string
	Status         int
	Time           int64
	Proto          string
	ContentLength  int64
}

func SendRequest

func SendRequest(req *Request, session *HttpSession) (*Response, error)

type ResponseParser

type ResponseParser struct {
	Response *Response
	Err      error
}

func (*ResponseParser) ReadToJsonObject added in v1.0.1

func (rp *ResponseParser) ReadToJsonObject() (*json.Object, error)

func (*ResponseParser) ReadToText

func (rp *ResponseParser) ReadToText() (string, error)

Jump to

Keyboard shortcuts

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