如何使用带有原始标头的 wget(或curl)复制请求?

发布于 2024-12-07 15:48:36 字数 694 浏览 1 评论 0原文

我正在调试一些 http 请求,发现我可以获取这种格式的请求标头:

GET /download?123456:75b3c682a7c4db4cea19641b33bec446/document.docx HTTP/1.1
Host: www.site.com
User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Referer: http://www.site.com/dc/517870b8cc7
Cookie: lang=us; reg=1787081http%3A%2F%2Fwww.site.com%2Fdc%2F517870b8cc7

Is it possible or is there a simple way to reconstruct that request using wget or curl (or another CLI tool?)

从阅读 wget 手册页我知道我可以单独设置其中几个内容,但是有没有更简单的方法可以从命令行发送包含所有这些变量的请求?

I was deubgging some http requests and found that I can grab request headers in this type of format:

GET /download?123456:75b3c682a7c4db4cea19641b33bec446/document.docx HTTP/1.1
Host: www.site.com
User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Referer: http://www.site.com/dc/517870b8cc7
Cookie: lang=us; reg=1787081http%3A%2F%2Fwww.site.com%2Fdc%2F517870b8cc7

Is it possible or is there an easy way to reconstruct that request using wget or curl (or another CLI tool?)

From reading the wget manual page I know I can set several of these things individually, but is there an easier way to send a request with all these variables from the command line?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼中杀气 2024-12-14 15:48:36

是的,您只需使用 --header 组合所有标头

wget --header="User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \
--header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
--header="Accept-Language: en-us,en;q=0.5" \
--header="Accept-Encoding: gzip, deflate"
--header="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" \
--header="Cookie: lang=us; reg=1787081http%3A%2F%2Fwww.site.com%2Fdc%2F517870b8cc7" \
--referer=http://www.site.com/dc/517870b8cc7
http://www.site.com/download?123456:75b3c682a7c4db4cea19641b33bec446/document.docx

如果您试图进行非法下载,
它可能会失败,
这取决于托管 URL 的编程方式

Yes, you just need to combine all the headers using --header

wget --header="User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \
--header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
--header="Accept-Language: en-us,en;q=0.5" \
--header="Accept-Encoding: gzip, deflate"
--header="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" \
--header="Cookie: lang=us; reg=1787081http%3A%2F%2Fwww.site.com%2Fdc%2F517870b8cc7" \
--referer=http://www.site.com/dc/517870b8cc7
http://www.site.com/download?123456:75b3c682a7c4db4cea19641b33bec446/document.docx

If you are trying to do some illegal download,
it might fail,
is depends on how hosting URL being programmed

浅浅淡淡 2024-12-14 15:48:36

这是 curl 版本:

curl http://www.example.com/download?123456:75b3c682a7c4db4cea19641b33bec446/document.docx \
-H "User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
-H "Accept-Language: en-us,en;q=0.5" \
-H "Accept-Encoding: gzip, deflate"
-H "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" \
-H "Cookie: lang=us; reg=1787081http%3A%2F%2Fwww.site.com%2Fdc%2F517870b8cc7" \
-H "Referer: http://www.example.com/dc/517870b8cc7"

在 Chrome 开发者工具中,您可以使用 Copy as cURL 将请求捕获为 curl

Here is curl version:

curl http://www.example.com/download?123456:75b3c682a7c4db4cea19641b33bec446/document.docx \
-H "User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
-H "Accept-Language: en-us,en;q=0.5" \
-H "Accept-Encoding: gzip, deflate"
-H "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" \
-H "Cookie: lang=us; reg=1787081http%3A%2F%2Fwww.site.com%2Fdc%2F517870b8cc7" \
-H "Referer: http://www.example.com/dc/517870b8cc7"

In Chrome developer tools, you can use Copy as cURL to catch request as curl.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文