Web Service系列之实例之使用http.client发送SOAP POST请求
2017-04-23 22:09
447 查看
原文链接: Web Service系列之实例之使用http.client发送SOAP POST请求
本文只给出代码, 更多内容请查看本系列另外一篇文章, Web Service系列之实例之使用urllib发送SOAP POST请求
完整代码:
本文只给出代码, 更多内容请查看本系列另外一篇文章, Web Service系列之实例之使用urllib发送SOAP POST请求
完整代码:
import sys, http.client import urllib.request host = "localhost:9000" SM_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <ns1:helloWorld xmlns:ns1="http://webservice.kylinux.com/"> <arg0>%s</arg0> <arg0>%s</arg0> </ns1:helloWorld> </SOAP-ENV:Body> </SOAP-ENV:Envelope> """ SoapMessage = SM_TEMPLATE%("Kylin", "Shu") #print(SoapMessage) #construct and send the header webservice = http.client.HTTPConnection(host) headers = {"Content-type": "text/xml; charset=\"UTF-8\""} webservice.request("POST", "/WS/HelloWorld/", body=SoapMessage, headers=headers) #headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} response = webservice.getresponse() #print(response.status, response.reason) data = response.read() print(data) webservice.close()
相关文章推荐
- Web Service系列之实例之使用urllib发送SOAP POST请求
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- 如何使用火狐下的两款接口测试工具RESTClient和HttpRequester发送post请求
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)