使用小程序的中wx.request()请求chatGpt流式接口的实现
可以成功接收到数据,但是遇到了下面的问题,就是在接收的数据如果是中文会出现乱码,英文没有问题,可以正常解析出来。
大家有遇到这个问题吗,求解,求解…
const requestTask = wx.request({
url: 'url',
enableChunked: true,
header: {
'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
}
})
requestTask.onChunkReceived(response => {
const arrayBuffer = response.data;
let unit8Arr = new Uint8Array(arrayBuffer)
let text = String.fromCharCode.apply(null, unit8Arr);
var str=new TextDecoder("utf-8").decode(unit8Arr)
//此处中文乱码
console.log(str)
})
setTimeout(()=>{
requestTask.abort();
},2000)