FandyPeng
FandyPeng
  • 发布:2022-05-22 13:57
  • 更新:2022-06-24 10:57
  • 阅读:233

【报Bug】uni.request 在iOS 平台访问特定接口的时候,数据解析出现乱码

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 11.6.2 (20G314)

HBuilderX类型: 正式

HBuilderX版本号: 3.4.7

手机系统: iOS

手机系统版本号: iOS 15

手机厂商: 苹果

手机机型: iPhone 13

页面类型: nvue

vue版本: vue2

nvue编译模式: fast

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
    const keyword = '周杰伦';  
const curpage = 1;  

const target_url =  
'https://c.y.qq.com/soso/fcgi-bin/client_music_search_songlist?' +  
'remoteplace=txt.yqq.playlist&format=json' +  
`&page_no=${curpage - 1}&num_per_page=20&query=${keyword}`;  
uni.request({  
    url: target_url,  
    header: {  
        Referer: 'https://y.qq.com/',  
        Accept: 'application/json; charset=utf-8',  
    },  
    success: (res) => {  
        console.log('api result: ', res)  
    }  
})

操作步骤:

以上代码使用 iOS 设备直接执行

预期结果:

中文解析正常

实际结果:

中文解析乱码

bug描述:

在 iOS 设备上,使用 uni.request 发起特定 url 的网络请求,返回数据是 json 格式,Android 设备解析正常,iOS 设备解析中文出现乱码,尝试过设置 http 的 request header,没有效果

2022-05-22 13:57 负责人:DCloud_iOS_DJX 分享
已邀请:
DCloud_iOS_DJX

DCloud_iOS_DJX

你抓包 看一下 iOS 和 Android 的参数有何不同?

  • FandyPeng (作者)

    iOS 和 Android 都真机运行上面的一段代码,抓包结果如下:

    Android:


    curl -H "Accept: application/json; charset=utf-8" -H "Referer: https://y.qq.com/"

    -H "user-agent: UNI-APP/1.0" -H "Host: c.y.qq.com"

    --compressed "http://c.y.qq.com/soso/fcgi-bin/client_music_search_songlist?remoteplace=txt.yqq.playlist&format=json&page_no=0&num_per_page=20&query=%E7%8E%8B%E5%BF%83%E5%87%8C"


    iOS:


    curl -H "Host: c.y.qq.com" -H "Accept: application/json; charset=utf-8" -H "Referer: https://y.qq.com/"

    -H "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Html5Plus/1.0 (Immersed/20) uni-app"

    -H "Accept-Language: zh-CN,zh-Hans;q=0.9"

    --compressed "http://c.y.qq.com/soso/fcgi-bin/client_music_search_songlist?remoteplace=txt.yqq.playlist&format=json&page_no=0&num_per_page=20&query=%E7%8E%8B%E5%BF%83%E5%87%8C"


    看起来 iOS 多了一个 header,Accept-Language,我在代码里面把这个 Accept-Language 设置成空值也是同样的结果,求大佬指点

    2022-05-26 23:12

  • DCloud_iOS_DJX

    回复 FandyPeng: 这个理论来说不应该影响你的请求才对 你们后端是有什么特殊要求吗?

    2022-06-06 09:46

  • FandyPeng (作者)

    回复 DCloud_iOS_DJX: 后端没什么特殊要求,但是客户端解析中文乱码,所以提 bug,希望你们能解决一下这种异常问题~

    2022-06-07 21:48

  • DCloud_iOS_DJX

    回复 FandyPeng: 你提供个可以稳定复现的demo吧

    2022-06-08 11:10

  • FandyPeng (作者)

    回复 DCloud_iOS_DJX: 我上面提交的示例代码,就是可以稳定复现的哦,新建个示例项目,把代码拷贝到 App.vue 执行,使用 iOS 设备真机执行,控制台打印的中文就是乱码

    2022-06-08 20:24

  • DCloud_iOS_DJX

    回复 FandyPeng: 我试了下 好像从qq音乐回来时的数据就是乱的 换了好几种编码格式也都不对 这里边是不是有啥特殊字符啊

    2022-06-14 21:09

  • DCloud_iOS_DJX

    回复 FandyPeng: {"code":0,"subcode":0,"message":"","default":0,"data":{"display_num":142406,"list":[{"copyrightnum":90,"createtime":"2015-08-14","creator":{"avatarUrl":"","creator_uin":"554310825","encrypt_uin":"7K4Poi6zNe-k","followflag":0,"isVip":0,"name":"💋ゞ  人间非净土﹎"","qq":554310825,"singerid":0,"singermid":"","type":0},"diss_status":300,"dissid":"2273731241","dissname":"经典重温刘德华","docid":2273731241,"imgurl":"http://p.qpic.cn/music_cover/iarc8OepZDsXKbTndmeIEv1wlzMbs01sYy35UFraLgr2hHgXJzFdIxg/600","introduction":"刘德华是华人娱乐圈影、视、歌多栖发展的代表之一

作为歌手,他是华人演艺圈演而ä¼...","listennum":9309532,"score":0.0,"song_count":94},{"copyrightnum":101,"createtime":"2021-07-30","creator":{"avatarUrl":"","creator_uin":"467578052","encrypt_uin":"7eCl7KSFoe4A","followflag":0,"isVip":0,"name":"咸鱼大饼干","qq":467578052,"singerid":0,"singermid":"","type":2},"diss_status":400,"dissid":"8097568427","dissname":"感谢遇见你:刘德华出道四十周年","docid":3802601131,"imgurl":"http://qpic.y.qq.com/music_cover/BxQgxonwzUDWO6IdGBmJ9icHNa03DBahWVTXiamI5TyqCjfOIddV36fg/300","introduction":"刘德华(Andy&nbsp&#59;Lau),1961å¹´9月出生于中国香港,中国知名演员、歌手、词作人、制片ä...","listennum":12685321,"score":0.0,"song_count":101},{"copyrightnum":31,"createtime":"2015-09-13","creator":{"avatarUrl":"","creator_uin":"2548933279","encrypt_uin":"ow4PNeEioi-lNv","followflag":0,"isVip":0,"name":"冯溪明","qq":2548933279,"singerid":0,"singermid":"","type":0},"diss_status":300,"dissid":"3478828817","dissname":"经典金曲.刘德华","docid":3478828817,"imgurl":"http://p.qpic.cn/music_cover/Hetf08iay3WdWxDzKPuykxJ4k7unvMSamXLFx2XLr0qeK6syH4c5QQg/600","introduction":"刘德华在娱乐圈,可是无人不知无人不晓他是四大天王之首,曾创造一个,经典的时代 ...","listennum":1833980,"score":0.0,"song_count":31},{"copyrightnum":196,"createtime":"2019-12-02","creator":{"avatarUrl":"","creator_uin":"919782311","encrypt_uin":"NK6q7icAoi65","followflag":0,"isVip":0,"name":"沉默是金","qq":919782311,"singerid":0,"singermid":"","type":0},"diss_status":500,"dissid":"7324058270","dissname":"刘德华(经典粤语国语歌单大全)","docid":3029090974,"imgurl":"http://p.qpic.cn/music_cover/LC3O6sywXQMYDBp2La8rFKVG1SB3v8VDurjkMugt4xKSiceUckhyNkw/600","introduction":"","listennum":593913,"score":0.0,"song_count":200},{"copyrightnum":981,"createtime":"2016-05-08","creator":{"avatarUrl":"","creator_uin":"117047451","encrypt_uin":"oK6loevl7e45","followflag":0,"isVip":0,"name":"殤","qq":117047451,"singerid":0,"singermid":"","type":0},"diss_status":500,"dissid":"1113892604","dissname":"刘德华专辑","docid":1113892604,"imgurl":"http://y.gtimg.cn/music/photo_new/T002R300x300M000001a2xuC37hCXS.jpg","introduction":" 华仔的经典 &#160&#59;&#160&#59;你值得拥有   ","listennum":614455,"score":0.0,"song_count":1000},{"copyrightnum":77,"createtime":"2017-02-20","creator":{"avatarUrl":"","creator_uin":"451836535","encrypt_uin":"7e45Neos7Kok","followflag":0,"isVip":0,"name":"故事该翻牌","qq":451836535,"singerid":0,"singermid":"","type":0},"diss_status":300,"dissid":"2354687995","dissname":"张学友  刘德华  郭富城  黎明","docid":2354687995,"imgurl":"http://p.qpic.cn/music_cover/4XicITmu6KUUHUWw4DOCUffAeFTAMdva6fXdqbcWgjMSfias3D5fM5sA/600","introduction":"香港四大天王指中国香港地区20世纪90年代初出现在歌坛的四位重要人物,他们是张学友...","listennum":590137,"score":0.0,"song_count":78},{"copyrightnum":93,"createtime":"2017-09-13","creator":{"avatarUrl":"","creator_uin":"2523668458","encrypt_uin":"ow4AoiCsNevkNn","followflag":0,"isVip":0,"name":"我是个讲道理的人","qq":2523668458,"singerid":0,"singermid":"","type":2},"diss_status":400,"dissid":"3278495658","dissname":"下次巡演还要约!刘德华演唱会live合集","docid":3278495658,"imgurl":"http://p.qpic.cn/music_cover/rbKoTQdkPFC5FFC95YibQL3PSWHQMpSdLPaibicjicm2Domibd6P5hqmnGQ/600","introduction":"其实能再听华仔演唱会的次数应该也不多了,所以对于他每次的巡演都倍感珍惜。当然...","listennum":11066266,"score":0.0,"song_count":95},{"copyrightnum":30,"createtime":"2016-09-06","creator":{"avatarUrl":"","creator_uin":"1787990180","encrypt_uin":"oKSF7iEqoe6Fon","followflag":0,"isVip":0,"name":"奋斗","qq":1787990180,"singerid":0,"singermid":"","type":0},"diss_status":500,"dissid":"834904082","dissname":"刘德华 99演唱会","docid":834904082,"imgurl":"http://y.gtimg.cn/music/photo/album_500/51/500_albumpic_477051_0.jpg","introduction":"","listennum":565907,"score":0.0,"song_count":30},{"copyrightnum":685,"createtime":"2017-07-24","creator":{"avatarUrl":"","creator_uin":"3243633069","encrypt_uin":"oi-PoiCioinsNv","followflag":0,"isVip":0,"name":"3243633069","qq":3243633069,"singerid":0,"singermid":"","type":0},"diss_status":300,"dissid":"3573606537","dissname":"一秒入魂!刘德华作品全集","docid":3573606537,"imgurl":"http://y.gtimg.cn/music/photo_new/T017R500x500M000001oxIZt0ar5cC.jpg","introduction":"","listennum":1139252,"score":0.0,"song_count":700},{"copyrightnum":102,"createtime":"2020-03-20","creator":{"avatarUrl":"","creator_uin":"542340682","encrypt_uin":"7KvAoivz7wcA","followflag":0,"isVip":0,"name":"清泽俊秀","qq":542340682,"singerid":0,"singermid":"","type":0},"diss_status":400,"dissid":"7483152612","dissname":"刘德华 | 天王出品 必是经典","docid":3188185316,"imgurl":"http://p.qpic.cn/music_cover/M1w0TZyE4TeOibpyF04y7iah1TxIuoYIQ0L2TkIjTxRJzdr2goUgdUxw/600","introduction":"香港四大天王之中,刘德华应该是人气最高,综合发展最好的一位,影视和歌曲方面都...","listennum":3824562,"score":0.0,"song_count":104},{"copyrightnum":50,"createtime":"2021-05-16","creator":{"avatarUrl":"","creator_uin":"1152921504712614297","encrypt_uin":"oK6kowEAoK4z7eS5owC57e-q7z","followflag":0,"isVip":0,"name":"仲夏夜星空","qq":105767321,"singerid":0,"singermid":"","type":0},"diss_status":400,"dissid":"7999197402","dissname":"刘德华:“華”语经典金曲50首","docid":3704230106,"imgurl":"http://qpic.y.qq.com/music_cover/dicGqbYQxsnACTpib8E6ET1gAYLtswicoicmqVC3ia0N5QYHXo9zAjChlWDUD944XRQEm/300","introduction":"刘德华,享誉华人娱乐圈的传奇人物,作为长红四十年经久不衰的明星典范,虽然出道...","listennum":4040437,"score":0.0,"song_count":50},{"copyrightnum":56,"createtime":"2017-01-22","creator":{"avatarUrl":"","creator_uin":"1215887192","encrypt_uin":"oK-57KcF7i6qoc","followflag":0,"isVip":0,"name":"🍃🍃✨","qq":1215887192,"singerid":0,"singermid":"","type":0},"diss_status":300,"dissid":"1449823059","dissname":"刘德华经典","docid":1449823059,"imgurl":"http://y.gtimg.cn/music/photo/album_500/65/500_albumpic_54665_0.jpg","introduction":"刘德华经典,经典情歌。","listennum":355022,"score":0.0,"song_count":57},{"copyrightnum":314,"createtime":"2017-02-15","creator":{"avatarUrl":"","creator_uin":"2407475174","encrypt_uin":"owvz7ivl7K6l7n","followflag":0,"isVip":0,"name":"梦淇儿。","qq":2407475174,"singerid":0,"singermid":"","type":0},"diss_status":300,"dissid":"1992849526","dissname":"张国荣,黄家驹,梅艳芳,刘德华","docid":1992849526,"imgurl":"http://p.qpic.cn/music_cover/O6KicBGDPA1umGln5GcdUYdb39zSpzBK98AwF26vJWdLqF6yadkGYRg/600","introduction":"黄家驹张国荣梅艳芳刘德华等港台歌手的歌都在这里,张国荣和梅艳芳因为一场比赛结...","listennum":146196,"score":0.0,"song_count":324},{"copyrightnum":40,"createtime":"2017-09-12","creator":{"avatarUrl":"","creator_uin":"314781768","encrypt_uin":"oi6P7ic57iCF","followflag":0,"isVip":0,"name":"Mamba Out","qq":314781768,"singerid":0,"singermid":"","type":0},"diss_status":500,"dissid":"3278370931","dissname":"刘德华粤语经典","docid":3278370931,"imgurl":"http://y.gtimg.cn/music/photo/album_500/38/500_albumpic_142538_0.jpg","introduction":"","listennum":92230,"score":0.0,"song_count":40},{"copyrightnum":73,"createtime":"2019-06-28","creator":{"avatarUrl":"","creator_uin":"2904004371","encrypt_uin":"owEz7enz7eolov","followflag":0,"isVip":0,"name":"今晚月色很美","qq":2904004371,"singerid":0,"singermid":"","type":0},"diss_status":300,"dissid":"7039735628","dissname":"无可替代刘德华","docid":2744768332,"imgurl":"http://y.gtimg.cn/music/photo_new/T001R500x500M000003aQYLo2x8izP.jpg","introduction":"刘德华 ,MH,JP(Andy Lau Tak-wah,1961å¹´9月27日-),香港著名演员兼歌手,1990年代获封é¦...","listennum":3219609,"score":0.0,"song_count":75},{"copyrightnum":21,"createtime":"2016-02-12","creator":{"avatarUrl":"","creator_uin":"365715616","encrypt_uin":"oiCk7i6k7w6s","followflag":0,"isVip":1,"name":"QQ音乐巅峰榜","qq":365715616,"singerid":0,"singermid":"","type":1},"diss_status":500,"dissid":"2603021547","dissname":"李荣浩刘德华领衔春节歌曲贺岁档","docid":2603021547,"imgurl":"http://p.qpic.cn/music_cover/VV0r92V7YpdU50dyfViaLvkEf2YuVmA0sbBIdh44WNCAvyKttKnCrqQ/600","introduction":"QQ音乐巅峰榜&nbsp&#59;数字音乐新方向
主持人:向南","listennum":3958656,"score":0.0,"song_count":21},{"copyrightnum":35,"createtime":"2020-02-28","creator":{"avatarUrl":"","creator_uin":"3233705956","encrypt_uin":"oi-ioiSz7KEk7c","followflag":0,"isVip":0,"name":"今天又忘记吃饭了","qq":3233705956,"singerid":0,"singermid":"","type":0},"diss_status":400,"dissid":"7449967953","dissname":"刘德华现场精选 · 经典永远","docid":3155000657,"imgurl":"http://p.qpic.cn/music_cover/5jNutIgus6eVebZYtB9uxw2djB46rzjzEICsCribjiasibAbpdoWMicF1g/600","introduction":"刘德华(Andy&nbsp&#59;Lau),1961å¹´9月27日出生于中国香港,籍贯广东新会&nbsp&#59;,中国香港男æ¼...","listennum":5049700,"score":0.0,"song_count":35},{"copyrightnum":32,"createtime":"2020-08-17","creator":{"avatarUrl":"","creator_uin":"545722971","encrypt_uin":"7Kvk7i-ANKS5","followflag":0,"isVip":0,"name":"林乐乐。","qq":545722971,"singerid":0,"singermid":"","type":0},"diss_status":400,"dissid":"7681233854","dissname":"刘德华 | 最受欢迎十大劲歌金曲","docid":3386266558,"imgurl":"http://qpic.y.qq.com/music_cover/W7suucKexcjnVj4NHH9SkbmHgBOLfJ2Bwa5HFsO9tSkRHF1mzoiacibw/300","introduction":"刘德华,著名演员和歌手。1990年代被封为香港“四大天王”之一,亦是大中华地区极å…...","listennum":2337598,"score":0.0,"song_count":32},{"copyrightnum":159,"createtime":"2018-12-18","creator":{"avatarUrl":"","creator_uin":"1152921504870380449","encrypt_uin":"oK6kowEAoK4z7ecloeoFoevPNv","followflag":0,"isVip":0,"name":"Mume","qq":263533473,"singerid":0,"singermid":"","type":0},"diss_status":500,"dissid":"6009128247","dissname":"刘德华演唱会现场版","docid":1714160951,"imgurl":"http://y.gtimg.cn/music/photo/album_500/51/500_albumpic_477051_0.jpg","introduction":"","listennum":418053,"score":0.0,"song_count":162},{"copyrightnum":18,"createtime":"2008-10-02","creator":{"avatarUrl":"","creator_uin":"178038075","encrypt_uin":"oKSFoeoFoeSk","followflag":0,"isVip":0,"name":"水坑","qq":178038075,"singerid":0,"singermid":"","type":0},"diss_status":500,"dissid":"10006075","dissname":"Wonderful World香港演唱会2007-刘德华","docid":10006075,"imgurl":"http://img.1ting.com/images/album/0208/s1_080201130742.jpg","introduction":"[ft=#ff0000,,]2007-2008å¹´,是刘德华的舞台年[/ft],wonderful&nbsp&#59;world&nbsp&#59;concert,9,10,11月在中国内å...","listennum":2516339,"score":0.0,"song_count":20}],"num_per_page":20,"page_no":0,"qc":[],"sum":142406,"uin":0}}

    2022-06-14 21:12

  • DCloud_iOS_DJX

    回复 FandyPeng: 你这个有文档说明吗 返回的是什么编码格式的

    2022-06-14 21:12

  • DCloud_iOS_DJX

    回复 DCloud_iOS_DJX: 大概明白了 他返回的东西 里有类似html的字符串 iOS的UTF8 编码不出来 在uniapp的iOS 端我们这时候用了一个兜底的方案 但是兜底的编码格式对于中文又处理的有问题 所以出现乱码 我们现在在兜底方案一下 再处理一下

    2022-06-15 15:18

  • FandyPeng (作者)

    回复 DCloud_iOS_DJX: 感谢大佬,希望新版本可以修复哈

    2022-06-18 00:48

DCloud_UNI_GSQ

DCloud_UNI_GSQ

HBuilderX 3.5.0 alpha 已修复

  • FandyPeng (作者)

    非常感谢!

    2022-07-22 23:05

要回复问题请先登录注册