asmcos / requests

A golang HTTP client library. Salute to python requests.
Other
665 stars 90 forks source link

post方法为什么不支持实时插入cookies呢? #11

Closed shoaly closed 4 years ago

shoaly commented 4 years ago

` //reset Cookies,

//Client.Do can copy cookie from client.Jar to req.Header

delete(req.httpreq.Header, "Cookie") `

源文件里面还专门去掉了..... 导致现在想要发送一个自定义cookie的 post 非常复杂, 不够优雅, 不够初衷了

` req := requests.Requests() cookie := &http.Cookie{ Name: "cooke_name", Value: "cookie_value", } req.SetCookie(cookie)

header := requests.Header{

    "content-type":              "application/x-www-form-urlencoded",
    "user-agent":                "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'",
}

payload := requests.Params{
    "snatch": clean_number(amount),
    "_token": _token,
    "id":     clean_number(id),
}

url_string := "https://......"
url_string = form_action
res, _ := req.Post(url_string, payload, header)`
asmcos commented 4 years ago

// cookies 是可以的,我写了一个测试的例子, request_test.go 里面有这个例子 // 我测试是成功的

    req = Requests()
cookie := &http.Cookie{}
cookie.Name = "postcookie"
cookie.Value = "20200725"
cookie.Path = "/"

req.SetCookie(cookie)

//test post cookies
resp, err = req.Post("https://www.httpbin.org/post", data)
if err == nil {
    coo := resp.Cookies()
    // coo is [] *http.Cookies
    println("********Post cookies*******")
    for _, c := range coo {
        fmt.Println(c.Name, c.Value)
    }
}
shoaly commented 4 years ago

额 我空了再试试看, 可能哪里理解错了 之前对go 还没那么了解 没仔细看源代码