Reread a response body from JavaScript's fetch

前端 未结 3 853
故里飘歌
故里飘歌 2021-01-03 22:53

fetch() returns promise which (if successful) resolves to a Response object. A very common thing to do is immediately call Response.json() to convert the respon

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-03 23:17

    Use Response.clone() to clone Response

    let clone = response.clone();
    

    Alternatively, use Response.body.getReader() which returns a ReadableStream to read Response as a stream, TextDecoder() to convert Uint8Array data stream to text.

提交回复
热议问题