发送xml over curl

wou*_*_be 5 xml post curl

我正在使用一个网页界面,允许我通过卷曲请求发布内容.

示例帖子如下所示:

<status>A note</status>
Run Code Online (Sandbox Code Playgroud)

但每当我尝试发送它时,它似乎都不接受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
Run Code Online (Sandbox Code Playgroud)

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

Fla*_*sne 7

要使用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
Run Code Online (Sandbox Code Playgroud)

要么

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
Run Code Online (Sandbox Code Playgroud)

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