wx.request访问api报307
发布于 4 年前 作者 leikang 1831 次浏览 来自 问答
wx.request({
 
      url: "https://zhiwen.qq.com/kg/InquiryEntity/", //接口url
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        //"apikey": Constant.API_KEY
      },
      method: "POST",
      data: {
        "Uin": "tester",
        "EntityName": "腾讯"//请求参数--实体名称
      },
      //res = {data: '开发者服务器返回的内容'}
      success: function (res) {
 
        console.log(res)
        if (res.statusCode != 200) {
          console.log('实体信息获取失败,请重试!')
          return
        }
        if ('Response' in res.data && 'Content' in res.data.Response) { //成功
          //跳转地址可以写相对路径,绝对路径一定要以/ 开头 这样写pages/air_quality/result是错误的
          // app.globalData.entityInquireResult = res.data.Response.Content;
          // console.log(res)
        } else {
          console.log('查询失败:请切换实体或检查网络')
        }
 
      },
      //失败,弹出modal
      fail: function () {
        //console.log(this); //这时候的this不是Page了
        console.log('查询失败:请检查网络')
      },
      //无论成功与失败,loading都取消
      complete: function () {
 
      }
    })
  • 当前 Bug 的表现(可附上截图)

https:请求安卓返回307,开发工具和iphone都正常,域名已经添加

  • 预期表现

200结果

  • 复现路径
  • 提供一个最简复现 Demo

直接用button发起上述请求即可

1 回复

你把请求改成GET试一下

回到顶部