xml 你如何发送 SOAP 请求?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11446822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:34:19  来源:igfitidea点击:

how do you send a SOAP request?

xmlhttpsoap

提问by SirBT

I am new to SOAP and xml. I read a number of tutorials but nothing seems to be clear enough.

我是 SOAP 和 xml 的新手。我阅读了许多教程,但似乎没有什么足够清楚的。

I am abit confused, Just how does one send an SOAP request? The way I have tried to do this is by saving my SOAP request (as seen below) as: testRequest.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>

I then open the file (testRequest.xml) with a browser in order for it to be sent..

然后我用浏览器打开文件 (testRequest.xml) 以便发送它..

what I get in return is an error message stating: XML Parsing Error: syntax error Location: localhost/projects/test.xml Line Number 1, Column 1:POST /MobileCashPayout.asmx HTTP/1.1 ^

我得到的回报是一条错误消息,说明: XML 解析错误:语法错误位置:localhost/projects/test.xml 行号 1,列 1:POST /MobileCashPayout.asmx HTTP/1.1 ^

Am I sending it the wrong way? Please help me out?

我是否以错误的方式发送它?请帮帮我?

回答by Miljen Mikic

Opening this document in browser wouldn't send a request. You have several options:

在浏览器中打开此文档不会发送请求。您有多种选择:

  • write a little script in any familiar language, script should connect to specified server and send a POST request with a body as mentioned in your message
  • use some of existing programs to do that for you
  • 用任何熟悉的语言编写一个小脚本,脚本应该连接到指定的服务器并发送带有消息中提到的正文的 POST 请求
  • 使用一些现有的程序来为你做这件事

If you're inexperienced I would definitely recommend second option. My personal favourite is SoapUI, see here.

如果您没有经验,我肯定会推荐第二个选项。我个人最喜欢的是 SoapUI,请看这里

回答by JohnMudd

This blog post helped me. Python SOAP Request using Requests

这篇博文帮助了我。 使用请求的 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))

回答by Kihats

On linux you can use curlto send the soap xml. Here's how to do it:

在 linux 上,您可以使用curl发送soap xml。这是如何做到的:

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT

Using the testRequest.xmlfile created you can

使用testRequest.xml创建的文件,您可以

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: ACTION_YOU_WANT_TO_CALL" --data @testRequest.xml URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT

Here is a linkthat describes the full process.

这是一个描述完整过程的链接

回答by Silmarillium

You cannot send a soap request when a browser as far as I know. I propose you use a tool like Soap UI

据我所知,您无法在浏览器时发送肥皂请求。我建议你使用像Soap UI这样的工具

to send a request.

发送请求。