【python 调用webserver】python请求调用webservices接口方法

python webservice接口调用,可以用requests包发起post请求方式,此方法稍微区别是data是XML格式数据。

config.py

from hashlib import md5
import datetime


# 请求地址
url="http://10.66.3.19:6039/BaseDataService.asmx"

# XML请求参数
#时间戳
# timeStamp=datetime.datetime.now().strftime('%Y%m%d%H%M%S')
timeStamp='20181023131042'
# 签名
timstamp_apitest=timeStamp+"APITEST"
md5_timstamp = md5(timstamp_apitest.encode('utf8')).hexdigest()
sign=md5_timstamp.upper()
print(sign)

# 开始日期
START_TIME='2020-10-14'
# 结束日期
END_TIME='2020-10-16'

# START_TIME=datetime.datetime.now().strftime('%Y-%m-%d')
# END_TIME=datetime.datetime.now().strftime('%Y-%m-%d')

webServerGetData.py

# -*- coding: utf-8 -*-
# author:laidefa
import requests
from config import *

# 设置headers
headers = {'Content-Type': 'text/xml;charset=UTF-8'}


# post XML请求参数
body="""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:TQMSExpertInterface>
         <!--Optional:-->
         <tem:sign>%s</tem:sign>
         <!--Optional:-->
         <tem:timeStamp>%s</tem:timeStamp>
         <!--Optional:-->
         <tem:method>TQMSAssayCheckInfo</tem:method>
         <!--Optional:-->
         <tem:data>
         <![CDATA[
              <ROOT><START_TIME>%s</START_TIME><END_TIME>%s</END_TIME><TYPE>TQMS</TYPE></ROOT>
         ]]>
         </tem:data>
      </tem:TQMSExpertInterface>
   </soapenv:Body>
</soapenv:Envelope>
"""%(sign,timeStamp,START_TIME,END_TIME)


print(body)
r = requests.post(url, data=body.encode("utf-8"), headers=headers)
print(r.status_code)

print(r.text)

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页