小程序访问webservice

ps:这两个都是在开发模式下执行通过,在正式发布听说会有https校验?没有测试过
第一种方式:这是调用不带参数的,带参数的待解决。

  WebSvcAccess:function()
  {
      var wsdlurl = "http://xxxx/xxx.asmx/HelloWorld";//填入自己的接口
      var tmpData= '<?xml version="1.0" encoding="utf-8"?>';
      tmpData+= '<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/">'; 
      tmpData+= '<soap:Body>';
      tmpData+= '<HelloWorld xmlns="http://tempuri.org/" />';     
      // tmpData+= '<desid>2021</desid>'; //带参数,失败了。。。
      tmpData+='</HelloWorld>';
      tmpData+= '</soap:Body>';
      tmpData+= '</soap:Envelope>';
      wx.request({
      url: wsdlurl,
      data: tmpData,
      method: 'POST',
      header: {
        'content-type':'text/xml; charset=utf-8',
        'SOAPAction': "http://tempuri.org/HelloWorld",
      },
      success: 
      function (res) {
        console.log(res);
      },
      fail:function(){
        console.log("请求失败");
      },
      complete:function(){
        console.log("请求完成");
      }
    })
  },

第二种方式:

  WebSvcAccess:function()
  {
      var wsdlurl = "http://xxxx/xxx.asmx/GetAllStudentScore";//填入自己的接口
      wx.request({
      url: wsdlurl,
      data: {
        'name':'value',//传入参数和值
      },
      method: 'POST',
      header: {
        'Content-Type':'application/x-www-form-urlencoded'
      },
      success: 
      function (res) {
        console.log(res);
      },
      fail:function(){
        console.log("请求失败");
      },
      complete:function(){
        console.log("请求完成");
      }
    })
  },
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容