访问 http://www.qqread.com/xml-soap/c347699.html
更多内容请看Python实用指南、Wlan组网----家庭专题、Python相关文章专题,或进入讨论组讨论。
为运行服务器,请打开另一个命令 shell 并执行 python calendar-ws.py 。执行结束时使用 ctrl-C 杀死进程。
我们本来可以用也是用 SOAP.py 写的客户机测试服务器,但那太显而易见了。我们还是用低级 Python 编写客户机把 SOAP 响应作为 XML 字符串来构建,并发送一条 HTTP 消息。这个程序(testcal.py)在 清单 3中。
清单 3:用 Python 核心库写的访问日历服务的客户机
import sys, httplib
SERVER_ADDR = "127.0.0.1"
SERVER_PORT = 8888
CAL_NS = "http://uche.ogbuji.net/ws/eg/simple-cal"
BODY_TEMPLATE = """<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:s="http://uche.ogbuji.net/eg/ws/simple-cal"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>
<SOAP-ENV:Body>
<s:getMonth>
<year xsi:type="xsd:integer">%s</year>
<month xsi:type="xsd:integer">%s</month>
</s:getMonth>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>"""
def GetMonth():
year = 2001
month = 12
body = BODY_TEMPLATE%(year, month)
blen = len(body)
requestor = httplib.HTTP(SERVER_ADDR, SERVER_PORT)
requestor.putrequest("POST", "cal-server")
requestor.putheader("Host", SERVER_ADDR)
requestor.putheader("Content-Type", "text/plain; charset="utf-8"")
requestor.putheader("Content-Length", str(blen))
requestor.putheader("SOAPAction", "http://uche.ogbuji.net/eg/ws/simple-car")
requestor.endheaders()
requestor.send(body)
(status_code, message, reply_headers) = requestor.getreply()
reply_body = requestor.getfile().read()
print "status code:", status_code
print "status message:", message
print "HTTP reply body:
", reply_body
if __name__ == "__main__":
GetMonth() 相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- Python实用指南 (220篇文章)
- Wlan组网----家庭专题 (4217篇文章)
- Python相关文章 (220篇文章)
- Python编程 (220篇文章)
- XMLHTTPRequest的属性和方法简介 (0次浏览)



