我希望在Linux机箱上向Apache服务器发送一个标头。如何通过cURL调用实现这一点?


当前回答

如果您想发送自定义标头,您可以这样做:

curl -v -H @{'custom_header'='custom_header_value'} http://localhost:3000/action?result1=gh&result2=ghk

其他回答

使用-H或--header。

手册页:http://curl.haxx.se/docs/manpage.html#-小时

在PHP中:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('HeaderName:HeaderValue'));

或者可以设置多个:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('HeaderName:HeaderValue', 'HeaderName2:HeaderValue2'));

我已经从curl转换为Httpie;语法如下:

http http://myurl HeaderName:value

GET(多个参数):

curl -X  GET "http://localhost:3000/action?result1=gh&result2=ghk"

or

curl --request  GET "http://localhost:3000/action?result1=gh&result2=ghk"

or

curl  "http://localhost:3000/action?result1=gh&result2=ghk"

or

curl -i -H "Application/json" -H "Content-type: application/json"  "http://localhost:3000/action?result1=gh&result2=ghk"

如果您想发送自定义标头,您可以这样做:

curl -v -H @{'custom_header'='custom_header_value'} http://localhost:3000/action?result1=gh&result2=ghk