对于某些项目,我需要在发送curl请求时激活cookie,然后在另一个调用中使用这些cookie。举个例子,让我们假设我想调用https://www.heise.de并将接收到的cookie保存在那里。当我用浏览器打开heise.de并查看我的cookie时,这就是它的样子
我假设这些是在连接到网站时生成的cookie。
对于测试,我现在想做同样的卷曲,我希望有一个类似的结果。
在Ubuntu控制台中,我尝试了以下操作
curl -L -c cookie.txt -b cookie.txt www.heise.de
当我打开文件时,我只看到:
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
所以,它生成文件,但我不明白,为什么那里没有cookie。我一定是错过了类似的东西,我在图像中看到的东西不应该在那里,或者什么的。
如能提供一些帮助,将不胜感激:)
发布于 2022-11-08 23:10:32
这很令人沮丧。
我尝试了我书中的所有技巧,这些技巧在过去帮助我得到了回应。
在我看来,这个网站不希望你和你的卷发或wget。
他们很擅长检测卷曲请求。
问题是,当使用curl发出请求时,此URL不返回标头中的cookie。对于我尝试过的一些请求头,根本没有响应。
下面是我卷曲https://www.heise.de/时的响应头
HTTP/2 200
server: nginx
date: Tue, 08 Nov 2022 22:58:40 GMT
content-type: text/html; charset=UTF-8
last-modified: Tue, 08 Nov 2022 22:58:40 GMT
age: 18
accept-ranges: bytes
strict-transport-security: max-age=15768000
x-frame-options: DENY
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-hacc-refreshed:
vary: Accept-Encoding, X-Export-Format, X-Export-Agent, X-Export-IAP
cache-control: no-store
content-length: 756164
我的女人:
wget -SO- -T 5 -t 1 https://www.heise.de/ > test.html
响应:
--2022-11-08 18:46:53-- https://www.heise.de/
Resolving www.heise.de (www.heise.de)... 2a02:2e0:3fe:1001:7777:772e:2:85, 193.99.144.85
Connecting to www.heise.de (www.heise.de)|2a02:2e0:3fe:1001:7777:772e:2:85|:443... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 08 Nov 2022 23:46:38 GMT
Content-Type: text/html; charset=UTF-8
Last-Modified: Tue, 08 Nov 2022 23:46:38 GMT
Age: 16
Accept-Ranges: bytes
Strict-Transport-Security: max-age=15768000
x-frame-options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Hacc-Refreshed:
Vary: Accept-Encoding, X-Export-Format, X-Export-Agent, X-Export-IAP
Cache-Control: no-store
Content-Length: 757423
Connection: keep-alive
Length: 757423 (740K) [text/html]
https://stackoverflow.com/questions/74354097
复制相似问题