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
+10.6k Golang : How to delete element(data) from map ?
+46.4k Golang : Encode image to base64 example
+10.3k Golang : Embed secret text string into binary(executable) file
+16k Golang : Read large file with bufio.Scanner cause token too long error
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+11.6k Golang : Concurrency and goroutine example
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+38.1k Golang : Read a text file and replace certain words
+28.2k Golang : Connect to database (MySQL/MariaDB) server
+25.7k Golang : missing Mercurial command
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters