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

httplib 

import httplib

    soapbody ='''
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:te="http://tempuri.org/">
            <soapenv:Header/>
            <soapenv:Body>
                <te:GetLisRequest>
                    <te:Barcode>%s</te:Barcode>
                    <te:LoginCode>%s</te:LoginCode>
                    <te:LoginPWD>%s</te:LoginPWD>
                    <te:DelegateHosCode>%s</te:DelegateHosCode>
                </te:GetLisRequest>
            </soapenv:Body>
        </soapenv:Envelope>'''

    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 ='''
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lns="http://tempuri.org/">
            <soapenv:Header/>
            <soapenv:Body>
                <lns:GetLisRequest>
                    <lns:Barcode>%s</lns:Barcode>
                    <lns:LoginCode>%s</lns:LoginCode>
                    <lns:LoginPWD>%s</lns:LoginPWD>
                    <lns:DelegateHosCode>%s</lns:DelegateHosCode>
                </lns:GetLisRequest>
            </soapenv:Body>
        </soapenv:Envelope>'''

    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)

 

转载于:https://www.cnblogs.com/dancesir/p/11164936.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值