On Wednesday, 12 September 2018 06:28:12 UTC+2, Weeds Qian wrote:
>
> What did you expect to see?
>
> the cookie in response
> What did you see instead?
>
> no cookie in response
>
>
> ------------------http tcp stream from wireshark 
> -----------------------------
>
> You can see that I only do the POST /login and the later is execute by 
> http client implementation.
>
> From my point of view, I think the GET /home.html request should add the 
> cookie from last response, but it didn't, since you don't do that, why 
> don't just return the response to me instead of doing useless request cause 
> we go the login page.
>
> POST /login HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: Go-http-client/1.1
> Content-Length: 28
> Content-Type: application/x-www-form-urlencoded
> Accept-Encoding: gzip
>
> username=admin&password=testHTTP/1.1 302 Found
> Location: /home.html
> Set-Cookie: 
> user=MTUzNjY1NjA2MXxEdi1CQkFFQ180SUFBUkFCRUFBQUpfLUNBQUVHYzNSeWFXNW5EQW9BQ0hWelpYSnVZVzFsQm5OMGNtbHVad3dIQUFWaFpHMXBiZz09fKI-QQWYHP_ZywpgkIoDmTzL1eJhd7pk-i9FSUgwI89E;
>  Path=/; HttpOnly
> Date: Tue, 11 Sep 2018 08:54:21 GMT
> Content-Length: 0
>
>  
There is your cookie.

The problem is not that the cookie is not part of the response
you get from /login but that you do not keep the cookie and
send it on subsequent requests:

>
> GET /home.html HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: Go-http-client/1.1
> Content-Type: application/x-www-form-urlencoded
> Referer: http://127.0.0.1:8081/login
> Accept-Encoding <http://127.0.0.1:8081/loginAccept-Encoding>: gzip
>
>
You see: No Cookie header here.

To record Set-Cookie headers and generate appropriate Cookie headers
from these set cookies you probably should use your own instance of
net/http.Client with a non-nil Jar and use that client to Do a POST request.
You can create a Jar via net/http/cookiejar.New.
If you are going to use this on arbitrary domains please consider setting
the Jar's PublicSuffixList to e.g. golang.org/x/net/publicsuffix.List

V.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to