3c92cce9 by astaxie

update httplib to support setcookie

1 parent fd78ea5c
...@@ -43,12 +43,20 @@ set post timeout: ...@@ -43,12 +43,20 @@ set post timeout:
43 ## debug 43 ## debug
44 if you want to debug the request info, set the debug on 44 if you want to debug the request info, set the debug on
45 45
46 httplib.Get("").Debug(true) 46 httplib.Get("http://beego.me/").Debug(true)
47 47
48 ## support HTTPS client 48 ## support HTTPS client
49 if request url is https. You can set the client support tls: 49 if request url is https. You can set the client support TSL:
50 50
51 httplib.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) 51 httplib.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
52 52
53 more info about the tls.Config please visit http://golang.org/pkg/crypto/tls/#Config 53 more info about the tls.Config please visit http://golang.org/pkg/crypto/tls/#Config
54 54
55 ## set cookie
56 some http request need setcookie. So set it like this:
57
58 cookie := &http.Cookie{}
59 cookie.Name = "username"
60 cookie.Value = "astaxie"
61 httplib.Get("http://beego.me/").SetCookie(cookie)
62
......
...@@ -89,6 +89,11 @@ func (b *BeegoHttpRequest) Header(key, value string) *BeegoHttpRequest { ...@@ -89,6 +89,11 @@ func (b *BeegoHttpRequest) Header(key, value string) *BeegoHttpRequest {
89 return b 89 return b
90 } 90 }
91 91
92 func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest {
93 b.req.Header.Add("Set-Cookie", cookie.String())
94 return b
95 }
96
92 func (b *BeegoHttpRequest) Param(key, value string) *BeegoHttpRequest { 97 func (b *BeegoHttpRequest) Param(key, value string) *BeegoHttpRequest {
93 b.params[key] = value 98 b.params[key] = value
94 return b 99 return b
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!