小程序 request 乱码问题
发布于 5 年前 作者 chenmin 12927 次浏览 来自 问答

发送 request GET 请求,返回的的结果为乱码。代码如下:

wx.request({
        url: 'https://wenku.qianjia.com/UploadFile/Document/%E6%99%BA%E8%83%BD%E5%AE%B6%E5%B1%85/%E5%AE%B6%E5%B1%85%E5%AE%89%E9%98%B2%E7%B3%BB%E7%BB%9F/%E8%A7%86%E9%A2%91%E7%9B%91%E6%8E%A7/8bfcbc10ea824fc788b500392a24c930/html/1.html',
        header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8' },
        method: "GET",
        success: function (res) {
            console.debug("请求详情成功!");
 
            let html = res.data;
            console.debug(html);
 
            /**
             * 1.数据的绑定键
             * 2.解析数据类型 html/md
             * 3.上下文
             * 4.解析文本中的图片 Padding 值
             * 5.解析文档中的图片的域名路径
             */
            WxParse.wxParse('details', 'html', html, that, 0, that.data.contentUrl);
        },
 
        fail: function () {
            console.debug("请求详情失败!");
        },
        complete: function () {
            console.debug("请求详情结束");
            wx.hideLoading();
        },
    });

该请求访问的是一个静态网页,而请求返回的结果在 模拟器上是正常的,而在 Android 手机上则是显示乱码。

2 回复

你这个网页的编码不是UTF8

<meta http-equiv=Content-Type content=“text/html; charset=gb2312”>

修改到UTF8既可

网页编码修改后也是乱码,而且直接在网页上访问也会编程乱码。

回到顶部