Answers:
只需-H
多次使用参数:
curl -H "Accept-Charset: utf-8" -H "Content-Type: application/x-www-form-urlencoded" http://www.some-domain.com
"
怎么办?
有时仅更改标题是不够的,某些站点也会检查引荐来源:
curl -v \
-H 'Host: restapi.some-site.com' \
-H 'Connection: keep-alive' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' \
-e localhost \
-A 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36' \
'http://restapi.some-site.com/getsomething?argument=value&argument2=value'
在此示例中,引荐来源网址(在curl中为-e或--referer)为“ localhost”。
要在curl请求中传递多个标头,您只需添加其他-H
或--header
到curl命令即可。
例
//Simplified
$ curl -v -H 'header1:val' -H 'header2:val' URL
//Explanatory
$ curl -v -H 'Connection: keep-alive' -H 'Content-Type: application/json' https://www.example.com
走得更远
对于标准HTTP标头字段,例如User-Agent,Cookie,Host,实际上还有另一种设置它们的方法。curl命令提供了用于设置这些标题字段的指定选项:
例如,以下两个命令是等效的。他们两个都在HTTP标头中更改“ User-Agent”字符串。
$ curl -v -H "Content-Type: application/json" -H "User-Agent: UserAgentString" https://www.example.com
$ curl -v -H "Content-Type: application/json" -A "UserAgentString" https://www.example.com