发送请求以使用来自文件的发布数据进行卷曲 [英] Send request to curl with post data sourced from a file

查看:75
本文介绍了发送请求以使用来自文件的发布数据进行卷曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从命令行通过Curl发出POST请求。该请求的数据位于文件中。我知道可以通过-upload-file 选项完成。

 卷曲主机:端口/后文件-H内容类型:文本/ xml-数据 contents_of_file 


解决方案

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

  curl -i -X POST主机:端口/后文件\ 
-H内容类型:文本/ xml \ \
--data-binary @ path / to / file

在示例中上面的 -i 打印出所有标题,以便您查看正在发生的情况,然后 -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.

这篇关于发送请求以使用来自文件的发布数据进行卷曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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