如何通过 cURL 调用使用 HTTP 请求发送标头?
问题描述:
我希望在 Linux 机器上向我的 Apache 服务器发送一个标头.如何通过 cURL 调用实现此目的?
I wish to send a header to my Apache server on a Linux box. How can I achieve this via a cURL call?
答
GET:
使用 JSON:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://hostname/resource
使用 XML:
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource
发布:
发布数据:
curl --data "param1=value1¶m2=value2" http://hostname/resource
文件上传:
curl --form "fileupload=@filename.txt" http://hostname/resource
RESTful HTTP Post:
curl -X POST -d @filename http://hostname/resource
用于登录站点(身份验证):
curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
curl -L -b headers http://localhost/