小程序请求后端数据错误

小程序用wx.request,请求后端数据的时候,为什么会一直被拦截?获取的数据是管理后台的登录页面,求解答,谢谢

img

  • 试不试后端有网关拦截或者token校验呢。

开发环境还是生产环境? 生产环境需要加https协议

【相关推荐】



  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7802409
  • 你也可以参考下这篇文章:微信小程序 在for循环中调用wx.request异步请求数据
  • 除此之外, 这篇博客: 小程序请求,wx.request 请求封装中的 小程序请求,wx.request 请求封装 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    
     // 提示与加载工具类
    export default class Tips {
        static success(title) {
        wx.showToast({
          title: title,
          icon: 'success',
          duration: 2000
        })
      }
      static error(title) {
        wx.showToast({
          title: title ||'出错啦~',
          image: '/static/images/error.png',
          mask: true,
          duration: 1500
        })
    }
    // 请求封装
        /**
        *@params url        string       接口地址
        *@params data       object       请求参数
    	*@prams  [method]   string     请求方式GET||POST
    	*@prams  [header]  string     请求头类型
        **/
         const host = 'localhost:8080'//仅为示例,并非真实的地址
    export function request(url, data, method, header) {
      wx.showLoading({
        title: '加载中' // 数据请求前loading
      })
      return new Promise((resolve, reject) => {
        wx.request({
          url: host + url, // 仅为示例,并非真实的接口地址
          method: method || 'POST',
          data: data,
          header: {
            'Authorization': '',
            'content-type': header || 'application/json', // 默认值
            'sign': '',
          }, //配置请求头
          success: function (res) {
              //请求成功回调
            wx.hideLoading();
            if (!res.data.success) {
              //请求有响应,但有异常
              Tips.error(res.data.msg)
            }
            resolve(res.data)
          },
            
          fail: function (error) {
              //请求失败
            wx.hideLoading();
            Tips.error(error.msg)
            reject(error.msg)
          },
          complete: function () {
            wx.hideLoading();
          }
        })
      })
    }
    export function get(url, data) {
      return request(url, data, 'GET')
    }
    export function post(url, data) {
      return request(url, data, 'POST')
    }
    

    使用方式

    import {
      request
    } from '@/utils/index.js'
    export const getActDetail = (params) => request('app/user?id='+params, {}, 'GET', '') 
    export const getActList = (params) => request('app/page', params, 'POST', '') 
    
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^