通过Curl发送在文件中指定的数据的POST请求 [英] Send POST Request with Data Specified in File via Curl
问题描述
我需要通过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@路径/到/文件
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
You're looking for the In the example above, 这篇关于通过Curl发送在文件中指定的数据的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
在上面的示例中, code>打印出所有的头文件,以便你可以看到发生了什么,
-X POST
明确表示这是一个职位。这两个都可以安全地省略,而不改变线上的行为。文件的路径前面需要有一个 @
符号,因此 curl
知道从文件中读取。 / p> --upload-file
option.curl host:port/post-file -H "Content-Type: text/xml" --data "contents_of_file"
--data-binary
argument:curl -i -X POST host:port/post-file -H "Content-Type: text/xml" --data-binary "@path/to/file"
-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.