Documentation ¶
Overview ¶
Example ¶
r := Post("https://httpbin.org/post", nil, url.Values{"hello": []string{"world"}}) var postResp struct { Form struct{ Hello string } } if err := r.JSON(&postResp); err != nil { log.Fatal(err) } fmt.Println(postResp.Form.Hello)
Output: world
Index ¶
- func SetAgent(agent string)
- func SetClient(c *http.Client)
- func SetNoProxy()
- func SetProxy(proxy string) error
- func SetProxyFromEnvironment()
- type File
- type H
- type Response
- func Get(url string, headers H) *Response
- func GetWithClient(url string, headers H, client *http.Client) *Response
- func Head(url string, headers H) *Response
- func HeadWithClient(url string, headers H, client *http.Client) *Response
- func Post(url string, headers H, data interface{}) *Response
- func PostWithClient(url string, headers H, data interface{}, client *http.Client) *Response
- func Upload(url string, headers H, params map[string]string, files ...*File) *Response
- func UploadWithClient(url string, headers H, params map[string]string, files []*File, ...) *Response
- type Session
- func (s *Session) Cookies(u *url.URL) []*http.Cookie
- func (s *Session) Get(url string, headers H) *Response
- func (s *Session) Head(url string, headers H) *Response
- func (s *Session) KeepAlive(interval time.Duration, fn func(*Session) error) (err error)
- func (s *Session) Post(url string, headers H, data interface{}) *Response
- func (s *Session) SetClient(c *http.Client)
- func (s *Session) SetCookie(u *url.URL, name, value string)
- func (s *Session) SetCookies(u *url.URL, cookies []*http.Cookie)
- func (s *Session) SetNoProxy()
- func (s *Session) SetProxy(proxy string) error
- func (s *Session) SetProxyFromEnvironment()
- func (s *Session) SetTimeout(d time.Duration)
- func (s *Session) Upload(url string, headers H, params map[string]string, files ...*File) *Response
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetProxyFromEnvironment ¶
func SetProxyFromEnvironment()
SetProxyFromEnvironment sets default client use environment proxy.
Types ¶
type File ¶
type File struct { io.ReadCloser Fieldname string Filename string }
File contains the file part of a multipart message.
type Response ¶
Response represents the response from an HTTP request.
func GetWithClient ¶
GetWithClient issues a GET to the specified URL with headers and client.
func HeadWithClient ¶
HeadWithClient issues a HEAD to the specified URL with headers and client.
func Post ¶
Post issues a POST to the specified URL with headers. Post data should be one of nil, io.Reader, url.Values, string map or struct.
func PostWithClient ¶
PostWithClient issues a POST to the specified URL with headers and client.
func Upload ¶
Upload issues a POST to the specified URL with a multipart document.
Example ¶
r := Upload("https://httpbin.org/post", nil, nil, F("readme", "README.md")) var resp struct { Files struct{ Readme string } Headers struct { ContentType string `json:"Content-Type"` } } if err := r.JSON(&resp); err != nil { log.Fatal(err) } fmt.Println(strings.Split(resp.Headers.ContentType, ";")[0])
Output: multipart/form-data
func UploadWithClient ¶
func UploadWithClient(url string, headers H, params map[string]string, files []*File, client *http.Client) *Response
UploadWithClient issues a POST to the specified URL with a multipart document and client.
func (*Response) JSON ¶
JSON parses the response body as JSON-encoded data and stores the result in the value pointed to by data.
type Session ¶
Session provides cookie persistence and configuration.
Example ¶
s := NewSession() s.Header.Set("hello", "world") s.Get("https://httpbin.org/cookies/set/name/value", nil) r := s.Get("https://httpbin.org/get", nil) var getResp struct { Headers struct{ Hello, Cookie string } } if err := r.JSON(&getResp); err != nil { log.Fatal(err) } fmt.Println(getResp.Headers.Hello, getResp.Headers.Cookie)
Output: world name=value
func NewSession ¶
func NewSession() *Session
NewSession creates and initializes a new Session using initial contents.
func (*Session) KeepAlive ¶ added in v1.0.1
KeepAlive repeatedly calls fn with a fixed interval delay between each call.
func (*Session) SetCookie ¶
SetCookie handles the receipt of the cookie in a reply for the given URL.
func (*Session) SetCookies ¶
SetCookies handles the receipt of the cookies in a reply for the given URL.
func (*Session) SetNoProxy ¶
func (s *Session) SetNoProxy()
SetNoProxy sets Session client use no proxy.
func (*Session) SetProxyFromEnvironment ¶
func (s *Session) SetProxyFromEnvironment()
SetProxyFromEnvironment sets Session client use environment proxy.
func (*Session) SetTimeout ¶
SetTimeout sets Session client timeout. Zero means no timeout.