2012-05-17 82 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

非常感謝,這幫助我完美。 –