使用 cURL 命令行 POST XML 文件 [英] POST XML file using cURL command line
问题描述
如何从命令行使用 cURL 将 XML 文件发布到本地服务器 http://localhost:8080
?
How can I POST an XML file to a local server http://localhost:8080
using cURL from the command line?
我应该使用什么命令?
推荐答案
如果该问题与您的其他 Hudson 问题相关,请使用他们提供的命令.从命令行使用 XML 的这种方式:
If that question is connected to your other Hudson questions use the command they provide. This way with XML from the command line:
$ curl -X POST -d '<run>...</run>' \
http://user:pass@myhost:myport/path/of/url
您需要稍微更改一下才能从文件中读取:
You need to change it a little bit to read from a file:
$ curl -X POST -d @myfilename http://user:pass@myhost:myport/path/of/url
阅读手册页.遵循 -d 参数的摘要.
Read the manpage. following an abstract for -d Parameter.
-d/--数据
(HTTP) 发送指定的数据POST 请求到 HTTP 服务器,在与浏览器相同的方式用户填写了一个 HTML 表单并且按下提交按钮.这会导致 curl 将数据传递给服务器使用内容类型应用程序/x-www-form-urlencoded.与 -F/--form 相比.
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F/--form.
-d/--data 与 --data-ascii 相同.要发布纯二进制数据,您应该而是使用 --data-binary 选项.对表单的值进行 URL 编码您可以使用 --data-urlencode 字段.
-d/--data is the same as --data-ascii. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data-urlencode.
如果这些选项中的任何一个被更多地使用在同一命令行上不止一次,指定的数据片段将是与分离合并在一起&-符号.因此,使用 '-d name=daniel-d Skill=lousy' 会生成一个看起来像的帖子块'name=daniel&skill=lousy'.
If any of these options is used more than once on the same command line, the data pieces specified will be merged together with a separating &-symbol. Thus, using '-d name=daniel -d skill=lousy' would generate a post chunk that looks like 'name=daniel&skill=lousy'.
如果数据以字母开头@,剩下的应该是一个文件名从中读取数据,或者 - 如果需要curl 从标准输入读取数据.这文件的内容必须已经是URL 编码.多个文件也可以被指定.从文件中发布数据名为 'foobar' 将因此完成--data @foobar.
If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. The contents of the file must already be URL-encoded. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar.
这篇关于使用 cURL 命令行 POST XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!