I'm trying to login to a website using curl and HTTP requests.
With the first http GET
request I add -c cookie.txt
to the command to save the cookie to a file. For the second curl POST I add -b cookie.txt
to pass the same cookie again.
Unfortunately I end up with a wrong session error message. When I compare the POST request with Chrome's POST
request I see that the cookie has more data than what's in my cookie.txt. When I copy Chrome's POST
using "copy as cURL command" I get for the cookie:
-H 'Cookie: PHPSESSID=rrh5d7l69tgl8633g3hklea2e0; POPUPCHECK=1140804027760'
But my cookie.txt only contains the PHPSESSID
. What am I not seeing here? Thank you!
Edit
I added the verbosity flag to the two commands and received this output:
curl -v https://my.host.com --cookie-jar cookie.txt
GET / HTTP/1.1
> Host: my.host.com
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Tue, 30 Oct 2018 09:39:05 GMT
< Server: Apache/2.2.22 (Debian)
* Added cookie PHPSESSID="psq8shk4l13fos9dc5536i8l36" for domain my.host.com, path /, expire 0
< Set-Cookie: PHPSESSID=psq8shk4l13fos9dc5536i8l36; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
* Replaced cookie PHPSESSID="hdctvsar28qqmgn6rmu33kidv4" for domain my.host.com, path /, expire 0
< Set-Cookie: PHPSESSID=hdctvsar28qqmgn6rmu33kidv4; path=/
< Vary: Accept-Encoding
< Content-Length: 3694
< Connection: close
< Content-Type: text/html; charset=utf-8
curl -v -X POST "https://my.host.com/" -H "Content-Type: application/x-www-form-urlencoded" -b cookie.txt
> POST / HTTP/1.1
> Host: my.host.com
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 73
>
* upload completely sent off: 73 out of 73 bytes
< HTTP/1.1 200 OK
< Date: Tue, 30 Oct 2018 09:39:06 GMT
< Server: Apache/2.2.22 (Debian)
* Added cookie PHPSESSID="lg9h4h8hlk69lrkosn0abpg7n7" for domain my.host.com, path /, expire 0
< Set-Cookie: PHPSESSID=lg9h4h8hlk69lrkosn0abpg7n7; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
* Replaced cookie PHPSESSID="r33haq0v45r4ofksrmm2ok86c5" for domain my.host.com, path /, expire 0
< Set-Cookie: PHPSESSID=r33haq0v45r4ofksrmm2ok86c5; path=/
< Vary: Accept-Encoding
< Content-Length: 3792
< Connection: close
< Content-Type: text/html; charset=utf-8
-v
flag for verbose output? It may give you more information to go on. Man page: curl.haxx.se/docs/manpage.html#-v – Haxiel Oct 29 '18 at 16:33