收藏
回答

utf-8 fail 紧急问题求救

框架类型 问题类型 操作系统 操作系统版本 手机型号 微信版本
小程序 Bug iOS iOS 12.1.2 iPhone 6 plus 7.0.3

前天已经在ide上把所有流程跑通了,昨天真机调试出现了这个error:'request:fail response data convert to UTF8 fail',想做一个模拟登录教务处获取成绩查询的小程序,也就是这个网站不是自己的,昨天整了一天看到很多要服务器返回编码改成'utf-8'的,我这边服务器自己控制不了,所以改不了。我用ide打印res.header得到的消息如下:

 在真机调试的时候,request直接失败进了fail,log是:


这是我的代码截图,请各位大仙帮忙看看,真的非常紧急,项目预定今天上线的,这是最后一个门槛了🤣🤣,如果有愿意帮忙调试的老哥,可以加我qq 307649087   我提供账号密码 🤣   可以有偿

// pages/login/login.js
//获取应用实例
const app = getApp()
 
Page({
  data: {
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    userName: null,
    userPwd: null,
    verificationCode: null,
    verificationImageUrl: null
  },
  //页面每次显示都要进行网络请求
  onShow: function () {
    wx.request({
      url: 'https://jwxt.jnu.edu.cn/ValidateCode.aspx',
      responseType: 'arraybuffer',
      success: res => {
        var mBase64 = wx.arrayBufferToBase64(res.data)
        this.setData({
          verificationImageUrl: 'data:image/png;base64,' + mBase64
        })
        app.globalData.userCookie = res.header['Set-Cookie']
        //缓存本地
        wx.setStorageSync('cookies', res.header['Set-Cookie'])
      }
    })
  },
 
  jnuLogin: function (e) {
    // 绑定的事件一般都传入个参数e,不填也ok
    var urlTmp = 'https://jwxt.jnu.edu.cn/Login.aspx/?__VIEWSTATE=%2FwEPDwUKMjA1ODgwODUwMg9kFgJmD2QWAgIBDw8WAh4EVGV4dAUk5pqo5Y2X5aSn5a2m57u85ZCI5pWZ5Yqh566h55CG57O757ufZGRk9KoyGrj1hrb%2FxZF6g8lZ2QQ9do4%3D&__VIEWSTATEGENERATOR=C2EE9ABB&__EVENTVALIDATION=%2FwEWBwLR44D1DQKDnbD2DALVp9zJDAKi%2B6bHDgKC3IeGDAKt86PwBQLv3aq9B47pXW7QJikyEA9%2B7Kos193HV3sp&txtYHBS=' + this.data.userName + '&txtYHMM=' + this.data.userPwd + '&txtFJM=' + this.data.verificationCode + '&btnLogin=%B5%C7++++%C2%BC'
    //1、登录
    wx.request({
      url: urlTmp,
      header: {
        'Cookie': app.globalData.userCookie,
        'content-type': app.globalData.content_type
      },
      success: function (res) {
        //判断登录是否成功
        //密码错误:你输入的用户名与口令不相符合
        //验证码错误:附加码不一致,请重新输入
        //学号错误:你输入的用户名与口令不相符合
        console.log(res.header)
        if (res.data.match(/用户名与口令不相符合(.*)/)) {
          wx.showModal({
            title: '提示',
            content: '用户名与口令不相符,请重新输入!',
          })
        } else if (res.data.match(/附加码不一致(.*)/)) {
          wx.showModal({
            title: '提示',
            content: '验证码不一致,请重新输入!',
          })
        } else {
          wx.showLoading({
            title: '加载中',
          })
 

          //2、’学分完成进度查询‘

//----⬇️-------  这里request失败,返回 utf-8 fail

          wx.request({
            url: 'https://jwxt.jnu.edu.cn/default.aspx',
            header: {
              'Cookie': app.globalData.userCookie,
              // 'Content-type':"text/html; charset=gb2312"
              'Content-type': app.globalData.content_type
            },
            success: res => {
              console.log(res.header)
              app.globalData.creditData = res.data
              //缓存本地
              // wx.setStorageSync('creditData', res.data)
            },
            fail: res => {
              console.log(res)
              app.globalData.creditData = res.data
            }
          })
 
        }
      }
    })
 
  }
})



最后一次编辑于  2019-02-19
回答关注问题邀请回答
收藏

1 个回答

  • 铭锋科技
    铭锋科技
    2019-02-19

    返回值编码

    • 建议服务器返回值使用 UTF-8 编码。对于非 UTF-8 编码,小程序会尝试进行转换,但是会有转换失败的可能。

    • 小程序会自动对 BOM 头进行过滤(只过滤一个BOM头)。


    2019-02-19
    有用
    回复 1
    • 2019-02-19

      老哥,问题是服务器那边不是我能控制的。。。  还有没有其它路子转码的

      2019-02-19
      回复
登录 后发表内容