How to send a header using a HTTP request through a curl call?

后端 未结 10 1395
梦如初夏
梦如初夏 2020-11-22 16:45

I wish to send a header to my Apache server on a Linux box. How can I achieve this via a curl call?

10条回答
  •  庸人自扰
    2020-11-22 17:35

    GET:

    with JSON:

    curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://hostname/resource
    

    with XML:

    curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource
    

    POST:

    For posting data:

    curl --data "param1=value1¶m2=value2" http://hostname/resource
    

    For file upload:

    curl --form "fileupload=@filename.txt" http://hostname/resource
    

    RESTful HTTP Post:

    curl -X POST -d @filename http://hostname/resource
    

    For logging into a site (auth):

    curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
    curl -L -b headers http://localhost/
    

提交回复
热议问题