代码之家  ›  专栏  ›  技术社区  ›  Nick Stinemates

我可以用urllib提交SOAP请求吗?

  •  3
  • Nick Stinemates  · 技术社区  · 16 年前

    我有一个SOAP请求,已知它使用类似于soapui的工具工作,但我正在尝试使用urlib使其工作。

    这是我迄今为止尝试过的,但没有起作用:

    import urllib
    f = "".join(open("ws_request_that_works_in_soapui", "r").readlines())
    urllib.urlopen('http://url.com/to/Router?wsdl', f)
    

    我还没有找到如何将文档发布到SOAP服务器的规范。

    Urllib不是必要的要求。

    2 回复  |  直到 7 年前
        1
  •  3
  •   Sergey Golovchenko    7 年前

    简短的回答:是的,你可以。

    长回答:

    看看这个 example 它不使用urllib,但会让您了解如何准备SOAP请求。

    至于Urllib,我建议使用 urllib2 ,是的,您可以使用它提交SOAP请求,按照与前面示例相同的步骤准备请求。

        2
  •  8
  •   Nick Stinemates    16 年前

    嗯,我回答了我自己的问题

    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)