cURL — cookies and sessions

前端 未结 1 1000
伪装坚强ぢ
伪装坚强ぢ 2020-12-06 06:02

I would like to understand the four options of cURL for cookies:

CURLOPT_COOKIESESSION  
CURLOPT_COOKIEFILE
CURLOPT_COOKIEJAR
CURLOPT_COOKIE
<
相关标签:
1条回答
  • 2020-12-06 06:29

    To understand CURLOPT_COOKIESESSION, you need to know a couple of things about cookies. Cookies have expiration dates that are set by the website that issues the cookie. If an expiration date of a cookie has passed, the browser/client will not send it, and it will be deleted by the client. If a cookie is set with NO expiration date, the browser should use that cookie until the browser session is closed, or the user logs out and the cookie gets unset.

    That said, CURLOPT_COOKIESESSION is a way to get cURL to simulate having closed the browser. If the COOKIEFILE has some session cookies in it (cookies with no expiration), it will normally send these if they were present in the file. If you set CURLOPT_COOKIESESSION, then it will NOT send any of the cookies that have no expiration date.

    CURLOPT_COOKIE just gives you a means of setting the cookie data that will be sent to the server in raw format. This is useful if for example you have a raw HTTP cookie that you would like to send. Without this option, you would have to get those cookies into the COOKIEFILE, or set a custom HTTP header Cookie: with the raw value you had.

    0 讨论(0)
提交回复
热议问题