通过Curl发送在文件中指定的数据的POST请求 [英] Send POST Request with Data Specified in File via Curl

查看:332
本文介绍了通过Curl发送在文件中指定的数据的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过Curl从命令行发出POST请求。此请求的数据位于文件中。我知道通过PUT可以使用 - 上传文件选项。

 code> curl host:port / post-file -HContent-Type:text / xml--datacontents_of_file


解决方案

您正在寻找 - data-binary 参数:

  curl -i -X POST host:port / post-file -HContent-Type:text / xml--data-binary@路径/到/文件



在上面的示例中, code>打印出所有的头文件,以便你可以看到发生了什么, -X POST 明确表示这是一个职位。这两个都可以安全地省略,而不改变线上的行为。文件的路径前面需要有一个 @ 符号,因此 curl 知道从文件中读取。 / p>

I need to make a POST request via Curl from the command line. Data for this request is located in a file. I know that via PUT this could be done with the --upload-file option.

curl host:port/post-file -H "Content-Type: text/xml" --data "contents_of_file"

解决方案

You're looking for the --data-binary argument:

curl -i -X POST host:port/post-file -H "Content-Type: text/xml" --data-binary "@path/to/file"

In the example above, -i prints out all the headers so that you can see what's going on, and -X POST makes it explicit that this is a post. Both of these can be safely omitted without changing the behaviour on the wire. The path to the file needs to be preceded by an @ symbol, so curl knows to read from a file.

这篇关于通过Curl发送在文件中指定的数据的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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