zoukankan      html  css  js  c++  java
  • python3.x 使用httppost方式调用webservice

    其实原理就是根据webservice协议指定的request的soap格式,用http post的method把参数传递过去就算是调用了,然后解析返回的soap就可以了

    鉴于网上python3.x 的http post 实现代码比较少,我贴一段:


    def InvokeWebservice(phone,msg):
        texturl='http://127.0.0.1:7789/SMSService.asmx?op=SendShortMessage'
        postcontent='<?xml version="1.0" encoding="utf-8"?>'
        postcontent+='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        postcontent+='<soap:Body>'
        postcontent+='<SendShortMessage xmlns="http://tempuri.org/">'
        postcontent+='<phonenum>'+phone+'</phonenum>'#参数
        postcontent+='<message>'+msg+'</message>'#参数
        postcontent+='</SendShortMessage>'
        postcontent+='</soap:Body>'
        postcontent+='</soap:Envelope>'
        req=urllib.request.Request(texturl,data=postcontent.encode('utf-8'),headers={'Content-Type': 'text/xml'})
        urllib.request.urlopen(req)


  • 相关阅读:
    bzoj 1858 线段树
    bzoj 1877 最小费用流
    bzoj 1833 数位dp
    Codeforces Round #285 (Div. 1) B
    HDU2028 Lowest Common Multiple Plus
    HDU5706 GirlCat
    HDU2022 海选女主角
    687E: TOF
    687D: Dividing Kingdom II
    687D: Dividing Kingdom II
  • 原文地址:https://www.cnblogs.com/rav009/p/5131167.html
Copyright © 2011-2022 走看看