okhttp

package module
v0.0.0-...-5af5f04 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: GPL-3.0 Imports: 16 Imported by: 0

README

okhttp

Documentation

Index

Constants

View Source
const (
	// Version
	Version = "v0.1.0"
)

Variables

View Source
var DefaultRequestTimeOut = 5 * time.Second

DefaultRequestTimeOut set a default request time out

View Source
var NoMatchHttpMethod = errors.New("no match request method")

NoMatchHttpMethod is errors

Functions

This section is empty.

Types

type H

type H map[string]interface{}

type Handler

type Handler func(*Response)

type Request

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

func Connect

func Connect(uri string) (*Request, error)

Connect created a connect request

func Delete

func Delete(uri string) (*Request, error)

Delete created a delete request

func Get

func Get(uri string) (*Request, error)

Get created a get request

func Head(uri string) (*Request, error)

Head created a head request

func NewRequest

func NewRequest(method, uri string) (r *Request, err error)

NewRequest 建立一个请求

func Options

func Options(uri string) (*Request, error)

Options created a options request

func Patch

func Patch(uri string) (*Request, error)

Patch created a patch request

func Post

func Post(uri string) (*Request, error)

Post created a post request

func Put

func Put(uri string) (*Request, error)

Put created a put request

func Trace

func Trace(uri string) (*Request, error)

Trace created a trace request

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string) *Request

AddHeader add request header

func (*Request) Do

func (r *Request) Do() (*Response, error)

Do returns response

func (*Request) GetHeaders

func (r *Request) GetHeaders() H

GetHeaders get all request header

func (*Request) Method

func (r *Request) Method() string

Method get http method

func (*Request) SetBasicAuth

func (r *Request) SetBasicAuth(username, password string) *Request

SetBasicAuth set username and password to header

func (*Request) SetBody

func (r *Request) SetBody(body io.Reader) *Request

SetBody sets request body

func (*Request) SetCookie

func (r *Request) SetCookie(cookie *http.Cookie) *Request

SetCookie set a cookie request header

func (*Request) SetDebug

func (r *Request) SetDebug(d bool) *Request

SetDebug set debug mode

func (*Request) SetForm

func (r *Request) SetForm(v url.Values) *Request

SetForm sets request form and returns response

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string) *Request

SetHeader set request header

func (*Request) SetHeaders

func (r *Request) SetHeaders(headers map[string]string) *Request

SetHeaders multi set request header

func (*Request) SetJSON

func (r *Request) SetJSON(v interface{}) *Request

SetJSON sets request JSON and returns response

func (*Request) SetPrintBody

func (r *Request) SetPrintBody(d bool) *Request

SetPrintBody set debug mode rely Debug

func (*Request) SetProxy

func (r *Request) SetProxy(proxyURL string) *Request

SetProxy set a referer request header

func (*Request) SetRedirects

func (r *Request) SetRedirects(i bool) *Request

SetRedirects set default request allow redirects

func (*Request) SetReferer

func (r *Request) SetReferer(referer string) *Request

SetReferer set a referer request header

func (*Request) SetTimeOut

func (r *Request) SetTimeOut(d time.Duration) *Request

SetTimeOut set default request time

func (*Request) SetUserAgent

func (r *Request) SetUserAgent(value string) *Request

SetUserAgent set user-agent

func (*Request) URL

func (r *Request) URL() *url.URL

URL url object

func (*Request) URLString

func (r *Request) URLString() string

URLString url string

type Response

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

Response r

func (*Response) GetBody

func (r *Response) GetBody() []byte

GetBody returns response body

func (*Response) GetCookies

func (r *Response) GetCookies() []*http.Cookie

GetCookies returns response cookies slice

func (*Response) GetHeader

func (r *Response) GetHeader(key string) string

GetHeader returns response header by name

func (*Response) GetHeaders

func (r *Response) GetHeaders() H

GetHeaders return response headers

func (*Response) GetJSON

func (r *Response) GetJSON(v interface{}) error

GetJSON unmarshal JSON response to struct

func (*Response) GetRequest

func (r *Response) GetRequest() *Request

GetRequest returns initial request

func (*Response) GetStatus

func (r *Response) GetStatus() int

GetStatus returns response status code

func (*Response) String

func (r *Response) String() string

String returns response body as string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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