Documentation ¶
Overview ¶
Package client provides an HTTP client for clean requests.
Package client provides cient request itilities.
Example ¶
package main import ( "fmt" "net/http" "os" "github.com/gowww/client" ) func main() { file, err := os.Open("data/one.txt") if err != nil { panic(err) } defer file.Close() req := client.Post("http://example.com"). DisableRedirect(). ForceMultipart(). Header("Accept-Language", "en"). UserAgent("Googlebot/2.1 (+http://www.google.com/bot.html)"). Cookie(&http.Cookie{Name: "session", Value: "123"}). Value("id", "123"). Value("name", "Doe"). File("file", "one.txt", file). OpenFile("picture", "one.png"). OpenFile("picture", "two.png") res, err := req.Do() if err != nil { panic(err) } defer res.Close() fmt.Println(res) }
Output:
Index ¶
- func Timeout(t time.Duration)
- type Request
- type Response
- func (r *Response) BodyBytes() ([]byte, error)
- func (r *Response) BodyString() (string, error)
- func (r *Response) Close() error
- func (r *Response) Cookie(name string) (*http.Cookie, error)
- func (r *Response) Dump()
- func (r *Response) JSON(v interface{}) error
- func (r *Response) Path() string
- func (r *Response) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Request ¶
type Request interface { Value(key, value string) Request File(key, filename string, file io.Reader) Request OpenFile(key, filepath string) Request Header(key, value string) Request Cookie(*http.Cookie) Request UserAgent(value string) Request DisableRedirect() Request ForceMultipart() Request Do() (*Response, error) String() string }
Request is a client request.
type Response ¶
Response is a request response wrapping the original *http.Request.
func (*Response) BodyString ¶
BodyString returns the response body as a string.
func (*Response) Close ¶
Close closes the response body. It must be called after body is no longer used.
func (*Response) Cookie ¶
Cookie returns the named cookie provided in the request or http.ErrNoCookie if not found. If multiple cookies match the given name, only one cookie will be returned.
func (*Response) Dump ¶
func (r *Response) Dump()
Dump is for debug purpose. It prints the request info, writes the body in a file and opens it in the browser. It panics on error.
Click to show internal directories.
Click to hide internal directories.