cURL 的 cookie-jar 选项和浏览器 cookie 之间的区别?

cURL 的 cookie-jar 选项和浏览器 cookie 之间的区别?

我正在尝试使用curl 和HTTP 请求登录网站。

在第一个 httpGET请求中,我添加了-c cookie.txt将 cookie 保存到文件的命令。对于第二个curl POST,我添加了-b cookie.txt再次传递相同的cookie。

不幸的是,我最终得到了错误的会话错误消息。当我将 POST 请求与 Chrome 的POST请求进行比较时,我发现 cookie 的数据比 cookie.txt 中的数据多。当我使用“复制为 cURL 命令”复制 Chrome 时,POST我得到了 cookie:

-H 'Cookie: PHPSESSID=rrh5d7l69tgl8633g3hklea2e0; POPUPCHECK=1140804027760'

但我的 cookie.txt 仅包含PHPSESSID.我在这里没有看到什么?谢谢你!

编辑

我向这两个命令添加了详细标志并收到了以下输出:

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

答案1

我的脚本有 Windows 风格的行结尾,由于某种原因,这把事情弄乱了。现在它正在工作,我只有\n行结尾。

相关内容