I have a SOAP request that is known to work using a tool like, say, SoapUI, but I am trying to get it to work using urllib.
我有一个SOAP请求,已知可以使用像SoapUI这样的工具,但我试图使用urllib来使其工作。
This is what I have tried so far and it did not work:
这是我到目前为止尝试过的,但是没有用:
import urllib
f = "".join(open("ws_request_that_works_in_soapui", "r").readlines())
urllib.urlopen('http://url.com/to/Router?wsdl', f)
I haven't been able to find the spec on how the document should be posted to the SOAP Server.
我无法找到关于如何将文档发布到SOAP服务器的规范。
urllib is not a necessary requirement.
urllib不是必需的。
2 个解决方案
#1
Short answer: yes you can.
简短回答:是的,你可以。
Long answer:
Take a look at this example it doesn't use urllib but will give you the idea of how to prepare SOAP request.
看一下这个例子,它不使用urllib,但会让你了解如何准备SOAP请求。
As far as urllib, I suggest using urllib2, and yes you can submit a SOAP request using it, follow the same steps to prepare the request as in previous example.
至于urllib,我建议使用urllib2,是的你可以使用它提交SOAP请求,按照前面的例子中的相同步骤准备请求。
#2
Well, I answered my own question
好吧,我回答了我自己的问题
import httplib
f = "".join(open('ws_request', 'r'))
webservice = httplib.HTTP('localhost', 8083)
webservice.putrequest("POST", "Router?wsdl")
webservice.putheader("User-Agent", "Python post")
webservice.putheader("Content-length", "%d" % len(f))
webservice.putheader("SOAPAction", "\"\"")
webservice.endheaders()
webservice.send(f)
#1
Short answer: yes you can.
简短回答:是的,你可以。
Long answer:
Take a look at this example it doesn't use urllib but will give you the idea of how to prepare SOAP request.
看一下这个例子,它不使用urllib,但会让你了解如何准备SOAP请求。
As far as urllib, I suggest using urllib2, and yes you can submit a SOAP request using it, follow the same steps to prepare the request as in previous example.
至于urllib,我建议使用urllib2,是的你可以使用它提交SOAP请求,按照前面的例子中的相同步骤准备请求。
#2
Well, I answered my own question
好吧,我回答了我自己的问题
import httplib
f = "".join(open('ws_request', 'r'))
webservice = httplib.HTTP('localhost', 8083)
webservice.putrequest("POST", "Router?wsdl")
webservice.putheader("User-Agent", "Python post")
webservice.putheader("Content-length", "%d" % len(f))
webservice.putheader("SOAPAction", "\"\"")
webservice.endheaders()
webservice.send(f)