levigross / grequests

A Go "clone" of the great and famous Requests library
Apache License 2.0
2.14k stars 138 forks source link

Repeated addition of HTTP headers #81

Closed wivd closed 5 years ago

wivd commented 5 years ago
opt  := &grequests.RequestOptions{}
    proxyURL, err := url.Parse("http://127.0.0.1:8080")
    //body := strings.NewReader("username=admin&password=password&Login=Login")

    opt.Headers = map[string]string{
        "test":"test",
    }

    opt.Proxies = map[string]*url.URL{proxyURL.Scheme: proxyURL}

    //opt.RequestBody = body
    opt.UseCookieJar = true
    opt.DisableCompression = false
    opt.Data =  map[string]string{"username":"admin","password":"password","Login":"Login"}

    resp,err := grequests.Post ("http://192.168.95.4/aaa/login.php",opt)
    fmt.Println(err)
    //fmt.Println(resp.String())
    fmt.Println(resp.StatusCode)

After login, the corresponding 302 status code of the web server,When grequests continues to make requests, the “test” header in the HTTP request header repeats http requests

GET /aaa/index.php HTTP/1.1
Host: 192.168.95.4
User-Agent: GRequests/0.10
Content-Type: application/x-www-form-urlencoded
Content-Type: application/x-www-form-urlencoded
Cookie: security=high; PHPSESSID=90949a1f57fa20a9e948f589e17a6786
Referer: http://192.168.95.4/aaa/login.php
Test: test
Test: test
Accept-Encoding: gzip, deflate
Connection: close

The reason is that the function "addRedirectFunctionality" in the utils. go file uses req. Header. Add (k, v) , Modified to req. Header.Set (k, v) resolves the problem of duplication of HTTP request headers

My English is very poor