xml - 这个 cURL 命令中的 -d 是什么意思?

标签 xml api rest curl get

我正在开发一个调用 RESTful api 的程序。 api 的所有文档都是 cURL 命令,但我不会制作 cURL 命令,因此我需要翻译它们并以不同的方式发出请求。这是他们为我想要进行的查询类型提供的示例代码。

curl -u '{userEmail}:{userApiToken}' -v -X GET -H 'Content-Type: application/xml' -o 'result.xml' -d '<request><layout>1</layout><searchmode>Cany</searchmode><searchvalue>aaron</searchvalue><filtermode></filtermode><filtervalue></filtervalue><special></special><limit>100</limit><start></start><sortfield></sortfield><sortdir></sortdir></request>' https://secure.website.com/contacts  `

我已经阅读了 cURL 文档并了解除 -d 之外的所有标志。我知道它的参数是搜索参数的 xml,但是 GET cURL 上的 -d 是什么意思?

谢谢

最佳答案

-d 指定请求的主体。来自手册页:

-d, --data (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 is the same as --data-ascii. --data-raw is almost the same but does not have a special interpretation of the @ character. 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.

有趣的是,您使用的服务将 GET 与请求主体结合使用,如 here, it is possible but unwanted 所述.

例如;允许代理人移走尸体。但是只要你和他们的服务器之间没有机器,它就可以工作;并且他们可能拥有允许他们解读 body 的软件。

关于xml - 这个 cURL 命令中的 -d 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32701551/

相关文章:

php - 使用 PHP 的 FedEx Shipping API

java - 在 Java 中,在发送 JSON POST 时使用 HttpPost(apache commons HttpClient)——我应该对正文进行 URL 编码吗?

xml - 在 GWT 客户端创建 XML 文档

python - 如何修复 bs4 选择错误 : 'TypeError: __init__() keywords must be strings'

ruby-on-rails - 在 Ruby 中从 XML 字符串创建对象

java - 1 个 View android 布局上的 2 个属性

iphone - 适用于iPhone的PDF417条形码api

php - 使用 post PHP 将图像上传到服务器

javascript - 如何序列化NodeJS?

java - 通过 Rest 调用在我的 Java 类中获取 JSON 结果