Is it possible to support cookiejar?
systemview2018 opened this issue · comments
ok
Does the following code meet your needs
package main
import (
"fmt"
"github.com/guonaihong/gout"
"net/http"
)
func main() {
// === 发送多个cookie ====
err := gout.
// :8080/cookie是http://127.0.0.1:8080/cookie的简写
GET(":8080/cookie").
//设置debug模式
Debug(true).
SetCookies(
//设置cookie1
&http.Cookie{
Name: "test1",
Value: "test1",
},
//设置cookie2
&http.Cookie{
Name: "test2",
Value: "test2",
},
).
Do()
if err != nil {
fmt.Println(err)
return
}
// === 发送一个cookie ===
err = gout.
// :8080/cookie/one是http://127.0.0.1:8080/cookie/one的简写
GET(":8080/cookie/one").
//设置debug模式
Debug(true).
SetCookies(
//设置cookie1
&http.Cookie{
Name: "test3",
Value: "test3",
},
).
Do()
fmt.Println(err)
}
if Client (*http.Client) is settable, It would be better.
jar, _ := cookiejar.New(nil)
client := &http.Client{
// example, custom cookie jar implements
Jar: jar,
// example, ignore self-signed certificate
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
}
err := gout.GET(":8080").Debug(true).
setClient(client).
Do()
fmt.Println(err)
thank you!
Use the New interface to set http.Client
jar, _ := cookiejar.New(nil)
client := &http.Client{
// example, custom cookie jar implements
Jar: jar,
// example, ignore self-signed certificate
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
}
err := gout.New(client).GET(":8080").Debug(true). Do()
fmt.Println(err)
Thanks for your answer.
这样的话这个(MaxIdleConnsPerHost)得设置
ok。我明天分析下。
…---Original---
From: ***@***.***>
Date: Fri, Mar 12, 2021 22:59 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [guonaihong/gout] Is it possible to support cookiejar? (#219)
@guonaihong
这样的话这个(MaxIdleConnsPerHost)得设置
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
@cute-angelia 是的,因为自定义的http.Client连接池。
这块我再确认下,我记得不设置MaxIdleConnsPerHost。默认值为2。