Golang net/http/cookiejar.New(), Cookies() and SetCookies() functions example
Example 1:
jar, _ := cookiejar.New(nil)
Example 2:
var cookies []*http.Cookie
...
fourthCookie := &http.Cookie{
Name: "dkv",
Value: "19a17a80fd703efd450d5ef9dadc32cee3QEAAAAdGxpcGn9mTBVMA==",
Path: "/",
Domain: ".youtube.com",
}
cookies = append(cookies, fourthCookie)
// URL for cookies to remember. i.e reply when encounter this URL
cookieURL, _ := url.Parse("https://www.youtube.com/results?search_query=")
jar.SetCookies(cookieURL, cookies)
Example 3:
fmt.Println(jar.Cookies(cookieURL))
See also : https://www.socketloop.com/tutorials/golang-storing-cookies-in-http-cookiejar-example
References :
http://golang.org/pkg/net/http/cookiejar/#New
Advertisement
Something interesting
Tutorials
+12.4k Golang : Extract part of string with regular expression
+24.6k Golang : How to validate URL the right way
+10k CodeIgniter : Load different view for mobile devices
+6.5k Golang : Map within a map example
+23.5k Golang : Read a file into an array or slice example
+8.2k Golang : Find relative luminance or color brightness
+26.7k Golang : How to check if a connection to database is still alive ?
+13.9k Golang : convert(cast) string to float value
+5.8k Golang : Launching your executable inside a console under Linux
+19.6k Golang : Get current URL example
+7.6k Javascript : Push notifications to browser with Push.js
+13.5k Golang : Count number of runes in string