且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过 cURL 调用使用 HTTP 请求发送标头?

更新时间:2022-04-05 05:39:24

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&param2=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/