wx.request调用webservcie返回statusCode: 500
发布于 6 年前 作者 jie36 14920 次浏览 来自 问答

调用webservice后进入到success: function了,但是没有返回到预期的数据

  1. errMsg"request:ok"data"<!DOCTYPE html> ↵<html> ↵    <head> ↵        <titl…le> ↵ ↵            <br> ↵ ↵    </body> ↵</html> ↵"statusCode500}

    1. data:"<!DOCTYPE html> ↵<html> ↵    <head> ↵        <title>运行时错误</title> ↵        <meta name="viewport" content="width=device-width" /> ↵        <style> ↵         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} ↵         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} ↵         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} ↵         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } ↵         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } ↵         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt} ↵         .marker {font-weight: bold; color: black;text-decoration: none;} ↵         .version {color: gray;} ↵         .error {margin-bottom: 10px;} ↵         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } ↵         [@media](/user/media) screen and (max-width: 639px) { ↵          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; } ↵         } ↵         [@media](/user/media) screen and (max-width: 479px) { ↵          pre { width: 280px; } ↵         } ↵        </style> ↵    </head> ↵ ↵    <body bgcolor="white"> ↵ ↵            <span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1> ↵ ↵            <h2> <i>运行时错误</i> </h2></span> ↵ ↵            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> ↵ ↵            <b> 说明: </b>服务器上出现应用程序错误。此应用程序的当前自定义错误设置禁止远程查看应用程序错误的详细信息(出于安全原因)。但可以通过在本地服务器计算机上运行的浏览器查看。 ↵            <br><br> ↵ ↵            <b>详细信息:</b> 若要使他人能够在远程计算机上查看此特定错误消息的详细信息,请在位于当前 Web 应用程序根目录下的“web.config”配置文件中创建一个 &lt;customErrors&gt; 标记。然后应将此 &lt;customErrors&gt; 标记的“mode”特性设置为“Off”。<br><br> ↵ ↵            <table width=100% bgcolor="#ffffcc"> ↵               <tr> ↵                  <td> ↵                      <code><pre> ↵ ↵&lt;!-- Web.Config 配置文件 --&gt; ↵ ↵&lt;configuration&gt; ↵    &lt;system.web&gt; ↵        &lt;customErrors mode=&quot;Off&quot;/&gt; ↵    &lt;/system.web&gt; ↵&lt;/configuration&gt;</pre></code> ↵ ↵                  </td> ↵               </tr> ↵            </table> ↵ ↵            <br> ↵ ↵            <b>注释:</b> 通过修改应用程序的 &lt;customErrors&gt; 配置标记的“defaultRedirect”特性,使之指向自定义错误页的 URL,可以用自定义错误页替换所看到的当前错误页。<br><br> ↵ ↵            <table width=100% bgcolor="#ffffcc"> ↵               <tr> ↵                  <td> ↵                      <code><pre> ↵ ↵&lt;!-- Web.Config 配置文件 --&gt; ↵ ↵&lt;configuration&gt; ↵    &lt;system.web&gt; ↵        &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt; ↵    &lt;/system.web&gt; ↵&lt;/configuration&gt;</pre></code> ↵ ↵                  </td> ↵               </tr> ↵            </table> ↵ ↵            <br> ↵ ↵    </body> ↵</html> ↵"

    2. errMsg:"request:ok"

    3. statusCode:500

具体代码如下,求大神指点!

wx.request({  

      url: ‘https://www.axiaoshuo.cn/MNWebService.asmx/Test’,

      data: {

        a: 3,

        b: 5

      },

      method: ‘POST’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT  

       header: { ‘content-type’: ‘application/json’ }, // 设置请求的 header  

      success: function(res){  

        // success  

        console.log(“success”)

        console.log(res)

        that.setData({motto:res.data.d})//这里是that不是this  

      },  

      fail: function(res) {  

        // fail  

        console.log(res)

      },  

      complete: function() {  

        // complete  

        //console.log(“complete”)

      }  

    })  

3 回复

谢谢楼上大神提供的思路,我的问题是出在网站的配置文件上了,需要在web.config文件中加入

<webServices>  

        <protocols>  

          <add name="HttpGet"/>  

          <add name="HttpPost"/>  

        </protocols>  

      </webServices>

我的环境是IIS7,webservcie是用asp.net做,我的配置如下:

<configuration>

  <system.web>

    <compilation targetFramework=“4.0” />

    <webServices>  

        <protocols>  

          <add name=“HttpGet”/>  

          <add name=“HttpPost”/>  

        </protocols>  

      </webServices>

    <httpRuntime />

    <customErrors mode=“Off”/>

  </system.web>

楼上,看你好像直接调用webservice url:https://www.axiaoshuo.cn/MNWebService.asmx/Test?a=3&b=4,

https://www.axiaoshuo.cn/MNWebService.asmx”这个是WSDL中 web service 的

<wsdlsoap:address location=“http://…/>么?

“Test”是调用的方法名么?

你要要求a+b=d吗

这是你服务器有问题。你可以先在浏览器测试。https://www.axiaoshuo.cn/MNWebService.asmx/Test?a=3&b=4

嗯。你服务器确实有问题,ping不通,你先看网站有没有问题吧。能不能访问。

回到顶部