这里怎么转字符都会乱码 但是用postman请求就没一点儿问题
const requestTask = wx.request({
url: 'https://ark.cn-beijing.volces.com/api/v3/bots/chat/completions',
method: 'POST',
enableChunked: true,
responseType: "arraybuffer", // 以 ArrayBuffer 格式接收数据
data: {
"model": '',
"messages": [{
"role": "user",
"content": "写一个文章"
}],
"stream": true,
},
header: {
'content-type': 'application/json',
'Authorization': 'Bearer xxx'
},
success: response => {},
fail: error => {}
});
requestTask.onChunkReceived((response) => {
const arrayBuffer = response.data;
const uint8Array = new Uint8Array(arrayBuffer);
const str = new TextDecoder('utf-8').decode(uint8Array);
console.log('str:',str)
});
如果不用流式,打印出来是正常的。
试试
const str = new TextDecoder('utf-8', { fatal: true }).decode(uint8Array);