发送xml over curl

前端之家收集整理的这篇文章主要介绍了发送xml over curl前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用一个网页界面,允许我通过卷曲请求发布内容.

示例帖子如下所示:

<status>A note</status>

但每当我尝试发送它时,它似乎都不接受XML

curl http://website.com/update -d '<?xml version="1.0" encoding="UTF-8"?><status>test</status>' -H 'Accept: application/xml' \ -H 'Content-Type: application/xml'  -u username:password

我可以做任何其他类型的请求,只是发送这个XML似乎不起作用,我在这里做错了什么?

解决方法

要使用curl发送数据(xml,json,text等),你必须使用POST方法添加–data-urlencode参数,如下所示:

curl -X POST http://website.com/update \
  --data-urlencode xml="<status>A note</status>" \
  -H 'Accept: application/xml' \
  -H 'Content-Type: application/xml' \
  -u username:password

要么

curl -X POST http://website.com/update \
  --data-urlencode "<status>A note</status>" \
  -H 'Accept: application/xml' \
  -H 'Content-Type: application/xml' \
  -u username:password

如果你想通过GET发送我认为你必须在调用curl命令之前编码字符串

猜你在找的XML相关文章