Save Response Body to file from curl request

2019-03-26 15:41发布

问题:

Im using curl against a webapi which knows to return a file for a particular post request (running this within browser would trigger the browser to pop up a "save file" dialog) . My intention is to have the response bytes written to a file. I use the following command

curl -k -i -u username:password -X POST -H "Content-Type:application/json" -d @c:\\curl\\request_body_file.json -o config.cfg https://127.0.0.1:8000/myapi/trigger/export

This however causes also the response header to be written to the output file, which is not my desire. I only need the response content saved.

This is how the output file looks like :

TTP/1.1 200 OK
Content-Length: 12042
Content-Type: application/octet-stream; charset=UTF-8
Content-Disposition: attachment; filename=my_export
Date: Wed, 23 Oct 2013 09:30:47 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.1.2
X-Auth-Token: Token ODVhMzk3OWY1NjcwMjg2ZGM0MDhmNTEzYTYwZmE4M2JhNTM1YmE0Yw==

xÚíÝÛãX~ØqÍÎŽçvfvervrevtrbyewd3334444 ................................ 

How would the curl command look in order to achive what I previously described.

Thanks

回答1:

From the curl docs:

-i, --include

(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...

so remove the -i param

http://curl.haxx.se/docs/manpage.html



回答2:

You could simply append the output to a file

curl ... >> output-file.html