2012-05-17 83 views
4

我正在使用一个web界面,允许我通过curl请求发布内容。通过curl发送xml

样本后看起来是这样的:

<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似乎不起作用,我在这里做错了什么?

+0

可能使用curl命令行复制[发送/发布xml文件](http:// stacko veronica.com/questions/3007253/send-post-xml-file-using-curl-command-line) – dkinzer

回答

6

发送使用curl你必须使用POST方法,并添加--data-urlencode参数,数据(XML,JSON,文本等),如所示波纹管:

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命令之前编码字符串

+0

非常感谢,这帮助我完美。 –