将响应正文保存到来自curl请求的文件

编程入门 行业动态 更新时间:2024-10-27 00:28:17
本文介绍了将响应正文保存到来自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 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参数

curl.haxx.se/docs/manpage.html

更多推荐

将响应正文保存到来自curl请求的文件

本文发布于:2023-10-29 13:10:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   正文   curl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!