gpt4 book ai didi

linux - 如何向每个 curl 命令发送相同的 cookie?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:15:24 30 4
gpt4 key购买 nike

我正在测试 curl,对这种语言很陌生。

让我解释一下我在做什么。

"http://somewebsite.com/click?param1=10&param2=523 "这是我在浏览器中点击并使用 Inspect Element 的 url,我得到了以下 curl bash 值 --

curl 'http://somewebsite.com/click?param1=10&param2=523' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.9' -H 'Cookie: pdval=9bc5d1fa982ff4c1e1f3d224' --compressed

现在每次我在浏览器中点击该 url 时,参数“pdval”的值都会发生变化。

是否有任何选项可以在 Linux 中使用 curl 读取 bash 脚本中的 -H 值。

任何帮助都会很棒。谢谢。

最佳答案

由于 pdval 在 cookie 中,您可以使用 -b-c cookie 相关任务的选项。

-c, --cookie-jar <文件名>

(HTTP) Specify to which file you want curl to write all cookies aftera completed operation. Curl writes all cookies from its in-memorycookie storage to the given file at the end of operations. If nocookies are known, no data will be written. The file will be writtenusing the Netscape cookie file format. If you set the file name to asingle dash, "-", the cookies will be written to stdout.

-b, --cookie <名称=数据>

(HTTP) Pass the data to the HTTP server in the Cookie header. It issupposedly the data previously received from the server in a"Set-Cookie:" line. The data should be in the format "NAME1=VALUE1;NAME2=VALUE2".

If no '=' symbol is used in the argument, it is instead treated as afilename to read previously stored cookie from.

因此,如果您设置 -c选项,然后 curl 将自动将 cookie 存储在文件中。而且你必须使用 -b告诉 curl 从该文件中获取 cookie。

所以你的命令应该如下:

curl 'http://somewebsite.com/click?param1=10&param2=523' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.9' -b /tmp/somewebsite.cookie -c /tmp/somewebsite.cookie --compressed

关于linux - 如何向每个 curl 命令发送相同的 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52849153/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com