当前位置:   article > 正文

fetch 流式请求_fetch请求流式接口识别到done报错

fetch请求流式接口识别到done报错
async function getStream() {
  try {
    let response = await fetch('/chat/stream/你好?'); //  /chat/stream/后面跟问题
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    const reader = response.body.getReader();
    const textDecoder = new TextDecoder();
    let isEnd = false;
    params.text = ''
    while (!isEnd) {
      const { done, value } = await reader.read();
      if (done) {
        isEnd = true
        break;
      }
      const chunkText = textDecoder.decode(value);
      console.log(chunkText,'qing')
      params.text += chunkText;
    }
  } catch (e) {
    console.log(e);
  }
}
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/335423?site
推荐阅读
相关标签
  

闽ICP备14008679号