虽然我过去使用过API,但这是我尝试使用的第一个SOAP.我从SOAP教程中复制,粘贴和更改了一些代码,但我已经看到它在10个不同的示例中以10种不同的方式完成,但没有一个在解释代码时非常清楚.也许以下代码不是最好的方法,但这就是为什么我正在寻找一些帮助和一个明确的方向进入.非常感谢.
import string, os, sys, httplib
server_addr = "auctions.godaddy.com"
service_action = "GdAuctionsBiddingWSAPI/GetAuctionList"
body = """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.example.com/services/wsdl/2.0">
<soapenv:Header/>
<soapenv:Body>
<ns:serviceListRequest>
<ns:userInfo>
</ns:userInfo>
</ns:serviceListRequest>
</soapenv:Body>
</soapenv:Envelope>"""
request = httplib.HTTPConnection(server_addr)
request.putrequest("POST", service_action)
request.putheader("Accept", "application/soap+xml, application/dime, multipart/related, text/*")
request.putheader("Content-Type", "text/xml; charset=utf-8")
request.putheader("Cache-Control", "no-cache")
request.putheader("Pragma", "no-cache")
request.putheader("SOAPAction", "https://auctions.godaddy.com/gdAuctionsWSAPI/gdAuctionsBiddingWS.asmx?op=GetAuctionList" + server_addr + service_action)
request.putheader("Content-Length", "length")
request.putheader("apiKey", "xxxxxx")
request.putheader("pageNumber", "1")
request.putheader("rowsPerPage", "1")
request.putheader("beginsWithKeyword", "word")
request.endheaders()
request.send(body)
response = request.getresponse().read()
print response
Run Code Online (Sandbox Code Playgroud)
use*_*342 10
不要试图滚动自己的SOAP客户端 - 尽管名称,SOAP不是简单的.
找到任何体面的SOAP库并将其用于SOAP通信.
一般来说,哪个SOAP库"最好"的问题本质上是有争议的,而且随着时间的推移,答案会随着时间的推移而变化,因为项目会逐渐变得过时.选择适合您的用例的那个,任何一个都可能比编写自己的更好.