--dump-header 写入文件后,如何将这些 header 读回下一个请求?我想从一个文件中读取它们,因为它们有很多。
我试过标准:cat headers | curl -v -H - ...
我实际上是使用 Firebug 中的功能来“复制请求 header ”,然后将它们保存到文件中。这似乎是相同的格式。
最佳答案
自 curl 7.55.0
简单:
$ curl -H @header_file $URL
...其中头文件是一个纯文本文件,每行都有一个 HTTP 头。像这样:Color: red
Shoesize: 11
Secret: yes
User-Agent: foobar/3000
Name: "Joe Smith"
在 curl 7.55.0 之前curl 无法像这样“批量更改”标题,甚至不能从文件中。
使用旧的 curl 版本的最佳方法可能是编写一个 shell 脚本来收集文件中的所有 header 并使用它们,例如:
#!/bin/sh
while read line; do
args="$args -H '$line'";
done
curl $args $URL
像这样调用脚本:$ sh script.sh < header_file
关于curl:从文件中读取标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12661159/