python 客户端 httplib 、 requests分别post数据(soap)

httplib 

import httplib

    soapbody ='''
        
            
            
                
                    %s
                    %s
                    %s
                    %s
                
            
        '''

    soapbody=soapbody %('0044636','1017','1017','5401762')
    webservice = httplib.HTTPS("hims-core-stg1.xxx.com.cn")
    webservice.putrequest("POST", "/lis/IHospitalInterface")
    webservice.putheader("Host", "hims-core-stg1.xxx.com.cn")
    webservice.putheader("Content-length", "%d" % len(soapbody))
    webservice.putheader("Content-type", "text/xml; charset=UTF-8")
    webservice.putheader("SOAPAction", "http://tempuri.org/IHospitalInterface/GetLisRequest")
    webservice.endheaders()
    webservice.send(soapbody)
    statuscode, statusmessage, header = webservice.getreply()

    res = webservice.getfile().read()

requests

import requests

body ='''
        
            
            
                
                    %s
                    %s
                    %s
                    %s
                
            
        '''

    payload=body %('0044636','1017','1017','5401762')

    url = "https://hims-core-stg1.xxx.com.cn/lis/IHospitalInterface"
    headers = {
        'Content-type': "text/xml; charset=UTF-8",
        'SOAPAction': "http://tempuri.org/IHospitalInterface/GetLisRequest",
        'Content-length': "%d" % len(payload),
        'Host': "hims-core-stg1.xxx.com.cn",
        }

    response = requests.request("POST", url, data=payload, headers=headers)

    print(response.text)

 

你可能感兴趣的:(python 客户端 httplib 、 requests分别post数据(soap))