how do you send a SOAP request?

前端 未结 5 956
攒了一身酷
攒了一身酷 2021-02-05 10:04

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

I am abit confused, Just how does one send an SOAP request? The way I have t

相关标签:
5条回答
  • 2021-02-05 10:33

    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

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

    0 讨论(0)
  • 2021-02-05 10:42

    This blog post helped me. Python SOAP Request using Requests

    #!/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))
    
    0 讨论(0)
  • 2021-02-05 10:49

    You can use postman. It is good for REST and Soap https://learning.postman.com/docs/sending-requests/supported-api-frameworks/making-soap-requests/

    0 讨论(0)
  • 2021-02-05 10:52

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

    to send a request.

    0 讨论(0)
  • 2021-02-05 10:55

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

    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.xml file created you can

    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 link that describes the full process.

    0 讨论(0)
提交回复
热议问题