- request 中的onChunkReceived 乱码
网页,postman ,接口都表现正常,开启 enableChunked: true, 后就乱码,求解 let task = wx.request({ url: 'https://xxx/api/chat/generate', enableChunked: true, method: "GET", }) task.onChunkReceived((buffer) => { // const decoder = new TextDecoder("utf-8"); // const str = decoder.decode(new Uint8Array(buffer.data)) const arrayBuffer = buffer.data; const uint8Array = new Uint8Array(arrayBuffer); let text = String.fromCharCode.apply(null, uint8Array); console.log('onChunkReceived',text) }) chrome表现 [图片] postman [图片] 后台接口 [图片] 乱码 [图片]
2023-05-18 - 小游戏中的RequestTask的onChunkReceived该如何调用?
const requestTask = wx.request({ url: 'www.baidu.com', header: { 'content-type': 'application/json' // 默认值 }, success (res) { console.log(res.data) } }); const listener = function (res) { console.log('onChunkReceived') } requestTask.onChunkReceived(listener); 以上代码运行时提示:TypeError: Cannot read property 'onChunkReceived' of undefined 使用的库为Wechat Lib:2.28.0 请问该如何才能使用?
2022-12-06