如何从中获取Cookie卷曲?

时间:2022-10-06 12:42:23

I am trying to get content of the page: I use google dev tool (network) and use "copy as curl" which gives me:

我想获取页面的内容:我使用谷歌开发工具(网络)并使用“复制为卷曲”,它给了我:

curl 'http://www.example.com/default.aspx/GetAnnonces' -H 'Cookie: `ASP.NET_SessionId=eolrcogrk1owhmpbsogwd0mf; EPC_alerte=;` 

This works fine for a while, I guess beacuse of the session life period.

这个工作正常一段时间,我想是因为会话生命期。

My question is:

我的问题是:

Where the SessionId "eolrcogrk1owhmpbsogwd0mf" comes from and how to generate it so I can access the page any time ?

SessionId“eolrcogrk1owhmpbsogwd0mf”来自何处以及如何生成它以便我可以随时访问该页面?

1 个解决方案

#1


1  

It comes from the Set-Cookie HTTP response header of the page you visited. If you're trying to use cURL in PHP it will automatically handle cookies for you and you can set CURLOPT_COOKIEJAR with curl_setopt to retain cookies even after the request is complete.

它来自您访问过的页面的Set-Cookie HTTP响应标头。如果您尝试在PHP中使用cURL,它将自动为您处理cookie,您可以使用curl_setopt设置CURLOPT_COOKIEJAR,以便在请求完成后保留cookie。

If you just want to see the response headers you could also use curl_setopt($handle, CURLOPT_HEADER, true) and look at the Set-Cookie response headers. Though there's no practical reason for doing this for most typical use cases since cURL will just handle the cookies for you like your browser would.

如果您只想查看响应头,还可以使用curl_setopt($ handle,CURLOPT_HEADER,true)并查看Set-Cookie响应头。虽然对于大多数典型的用例来说没有实际的理由这样做,因为cURL会像你的浏览器一样为你处理cookie。

#1


1  

It comes from the Set-Cookie HTTP response header of the page you visited. If you're trying to use cURL in PHP it will automatically handle cookies for you and you can set CURLOPT_COOKIEJAR with curl_setopt to retain cookies even after the request is complete.

它来自您访问过的页面的Set-Cookie HTTP响应标头。如果您尝试在PHP中使用cURL,它将自动为您处理cookie,您可以使用curl_setopt设置CURLOPT_COOKIEJAR,以便在请求完成后保留cookie。

If you just want to see the response headers you could also use curl_setopt($handle, CURLOPT_HEADER, true) and look at the Set-Cookie response headers. Though there's no practical reason for doing this for most typical use cases since cURL will just handle the cookies for you like your browser would.

如果您只想查看响应头,还可以使用curl_setopt($ handle,CURLOPT_HEADER,true)并查看Set-Cookie响应头。虽然对于大多数典型的用例来说没有实际的理由这样做,因为cURL会像你的浏览器一样为你处理cookie。