你如何发送SOAP请求?

Sir*_*rBT 15 xml soap http

我是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 ^

我发错了吗?请帮帮我?

Mil*_*kic 17

在浏览器中打开此文档不会发送请求.你有几个选择:

  • 用任何熟悉的语言编写一个小脚本,脚本应该连接到指定的服务器并发送一个POST请求,如消息中所述
  • 使用一些现有的程序为您做到这一点

如果你没经验我肯定会推荐第二种选择.我个人最喜欢的是SoapUI,请看这里.


Joh*_*udd 7

这篇博文对我有所帮助. 使用请求的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)