消费Web服务的Curl命令行?

47

你们知道如何使用Curl命令行向Web服务测试POST SOAP吗?

我有一个文件(soap.xml),其中附有所有的SOAP消息,但我似乎无法正确地发布它。

谢谢!

5个回答

43

发送字符串:

curl -d "String to post" "http://www.example.com/target"

发布文件的内容:

curl -d @soap.xml "http://www.example.com/target"

22
通常也需要包含此标头:-H "Content-Type: application/soap+xml;charset=UTF-8" - tokland
2
收到“HTTP/1.1 415 Unsupported Media Type”意味着内容类型标头缺失或错误。尝试使用此处建议的其中一种(“application/soap+xml”对我无效,但“text/xml”有效)。 - Nickolay
1
我还必须在“Content-Type”头中添加; action=http://tempuri.org/WhateverAction - Egor Tensin

34

我通常使用以下代码来访问SOAP 1.2 Web服务:

curl --header "content-type: application/soap+xml" --data @filetopost.xml http://domain/path

27

错了。对我没用。

对我来说,这个可以用:

curl 
-H 'SOAPACTION: "urn:samsung.com:service:MainTVAgent2:1#CheckPIN"'   
-X POST 
-H 'Content-type: text/xml'   
-d @/tmp/pinrequest.xml 
192.168.1.5:52235/MainTVServer2/control/MainTVAgent2

4
太棒了!感谢您抽出时间发布实际可行的示例! - Toran Billups

8
curl -H "Content-Type: text/xml; charset=utf-8" \
-H "SOAPAction:" \
-d @soap.txt -X POST http://someurl

1
иҝҷеҜ№жҲ‘жңүж•ҲгҖӮдҪҶжҳҜпјҢжҲ‘йңҖиҰҒд»Һж–Ү件дёӯиҜ»еҸ–soap.txtдёӯзҡ„еҖјгҖӮд»Јз Ғ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:usa="" rel = "nofollow noreferrer">http://www.xyz.com/SAFSubscriberProvision/"> soapenv:Header/ soapenv:Body <saf:SubscriberID MSISDN="254727849628"/> </soapenv:Body> </soapenv:Envelope> д»Јз Ғ - bernie
1
-d @soap.txt 参数提供了你想要的。 - Ahmet Karakaya

4
如果你想要一个比终端更加友好的界面,http://hurl.it/ 是一个很棒的选择。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接