Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save Response Body to file from curl request

Tags:

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

like image 412
klaus johan Avatar asked Oct 23 '13 09:10

klaus johan


People also ask

How do I redirect a curl output to a file?

Like in: curl http://{one,two}.site.com -o "file_#1. txt" or use several variables like: curl http://{site,host}.host[1-5].com -o "#1_#2" You may use this option as many times as the number of URLs you have. See also the --create-dirs option to create the local directories dynamically.

What is the curl option to save the body of the resulting response to a file?

By default, curl prints the response to screen. To make it save the response to a file, use the -o file command line option.

How do I save a curl script?

cURL commands can download files from a remote location. You can do it in two different ways: -O will save the file in the current working directory with the same file name as remote. -o lets you specify a different file name or location.


1 Answers

You could simply append the output to a file

curl ... >> output-file.html
like image 132
Daniel van Flymen Avatar answered Oct 12 '22 08:10

Daniel van Flymen