我是SOAP和xml的新手.我阅读了一些教程,但似乎没有什么比这更清楚了.
我很困惑,一个人如何发送SOAP请求?我尝试这样做的方法是将我的SOAP请求(如下所示)保存为:testRequest.xml.
POST /MobileCashPayout.asmx HTTP/1.1
Host: 192.168.1.80
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<Payout xmlns="http://www.mycel.com/">
<Username>string</Username>
<Password>string</Password>
<referenceID>string</referenceID>
<sourceMsisdn>string</sourceMsisdn>
<destMsisdn>string</destMsisdn>
<Amount>decimal</Amount>
<MobilePin>string</MobilePin>
<cashInformation>string</cashInformation>
<merchantName>string</merchantName>
</Payout>
</soap12:Body>
</soap12:Envelope>
Run Code Online (Sandbox Code Playgroud)
然后我用浏览器打开文件(testRequest.xml),以便发送它.
我收到的是一条错误消息,指出:XML解析错误:语法错误位置:localhost/projects/test.xml第1行,第1列:POST /MobileCashPayout.asmx HTTP/1.1 ^
我发错了吗?请帮帮我?
这篇博文对我有所帮助. 使用请求的Python SOAP请求
#!/usr/bin/env python
# encoding: utf-8
import requests
from XML import XML
request = u"""<?xml version="1.0" encoding="utf-8"?>
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:header>
<soapenv:body>
<web:conversionrate>
<web:fromcurrency>GBP</web:fromcurrency>
<web:tocurrency>CHF</web:tocurrency>
</web:conversionrate>
</soapenv:body>
</soapenv:header></soapenv:envelope>"""
encoded_request = request.encode('utf-8')
headers = {"Host": "www.webservicex.net",
"Content-Type": "text/xml; charset=UTF-8",
"Content-Length": len(encoded_request)}
response = requests.post(url="http://www.webservicex.net/CurrencyConvertor.asmx",
headers = headers,
data = encoded_request,
verify=False)
print unicode(XML(response.text))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
75639 次 |
最近记录: |