将响应正文保存到来自curl请求的文件 [英] Save Response Body to file from curl request

查看:563
本文介绍了将响应正文保存到来自curl请求的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用curl对webapi知道返回一个特定的post请求的文件(在浏览器中运行这将触发浏览器弹出一个保存文件对话框)。我的意图是将响应字节写入文件。我使用以下命令

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.

这是输出文件的外观:

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 ................................ 

curl命令如何查看以前的描述。

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

感谢

推荐答案

从curl文档:

-i,--include

-i, --include

(HTTP)在输出中包含HTTP标头。 HTTP头包括服务器名称,文档日期,HTTP版本等内容...

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

因此删除-i参数

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

这篇关于将响应正文保存到来自curl请求的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆