uniapp实现流式请求
uniapp实现流式请求
try { const requestTask = uni.request({ url: baseURL+'/ai/callChatAiflux', method: 'POST', headers: { 'Content-Type': 'application/json', // 如果需要认证,可加: // 'Authorization': 'Bearer ' + token }, data: JSON.stringify({ "text": userMessage.content }), enableChunked: true, //开启分块传输 transfer-encoding chunked success: (res) => { console.log('request success', res.data) // aiResponse.content = aiResponse.content + event.data; }, fail: (error) => { console.log('request fail', error) // ... } }) } catch (error) { throw new Error(`request error: ${error.message || '请求异常'}`) }

浙公网安备 33010602011771号