评论

SSE 接收到的参数怎么转化成字符串

怎么办流式请求返回的数据 转成字符串

// 流式请求

        const requestTask = wx.request({

          url: "",

          enableChunked: true, // 开启流式传输

          header: {

            'Authorization': token,

            "Content-Type": "application/json;charset=UTF-8",

          },

          method: "post",

          responseType: "text",

          data: paramData,

          timeout: 200000,

          success: (res1) => {

            console.info("获取成功: ", res1);

            _this.scrollToBottom();

          },

          fail(err) {

            console.log(err, "err");

            showToast('发送失败,请重试');

          },

        });

        requestTask.onChunkReceived((res) => {

          if (res.data) {

            let data = new TextDecoder().decode(res.data)

            console.log(data)

          }

        });

        requestTask.onHeadersReceived((res) => {

          console.log(res)

        });

      },

      fail: function (err) {

      }

    })


最后一次编辑于  11-26  
点赞 0
收藏
评论
登录 后发表内容