cookiejar 自动存储cookie

最后更新于:2022-04-02 02:44:48

[TOC] ## cookiejar cookiejar会自动帮忙管理服务端返回的cookies ``` jar, _ := cookiejar.New(nil) c := http.Client{ Jar: jar, } request, _ := http.NewRequest("get", "http://127.0.0.1:84", nil) c.Do(request) fmt.Printf("%+v\n", len(request.Cookies())) // 0 request, _ = http.NewRequest("get", "http://127.0.0.1:84", nil) c.Do(request) fmt.Printf("%+v\n", len(request.Cookies())) // 1 request, _ = http.NewRequest("get", "http://127.0.0.1:84", nil) c.Do(request) fmt.Printf("%+v\n", len(request.Cookies())) // 1 ```
';