cURLのCookiejarオプションとブラウザCookieの違いは何ですか?

cURLのCookiejarオプションとブラウザCookieの違いは何ですか?

カールとHTTPリクエストを使用してWebサイトにログインしようとしています。

最初のhttpリクエストでCookieをファイルに保存するコマンドをGET追加しました。 2番目のカールPOSTでは、同じCookieの再配信を-c cookie.txt追加しました。-b cookie.txt

残念ながら、間違ったセッションエラーメッセージが表示されました。 POSTリクエストをChromeのリクエストと比較すると、POSTCookieにcookie.txtにあるよりも多くのデータがあることがわかります。 「cURL コマンドでコピー」を使用して Chrome をコピーすると、POSTCookie が生成されます。

-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行末のみです。

おすすめ記事