The fetch
function returns a Promise that resolves with a Body
response.
Paraphrased from Mozilla: Fetch and Mozilla: Body :
The fetch() method... returns a Promise that resolves to the Response to that request, whether it is successful or not... Once a Response is retrieved, there are a number of methods available to define what the body content is and how it should be handled.
If you then navigate to the documentation for Body
you can see that it has a number of methods on it. The Body.text()
method:
Takes a Response stream and reads it to completion. It returns a promise that resolves with a USVString (text). The response is always decoded using UTF-8.
The behavior you've described is how the fetch
API is expected to behave.
The Fetch API returns a promise which resolves to a Response. The Response itself has a text() method which returns a promise as well. You can use this method to read the Response-Stream as a text. See https://developer.mozilla.org/en-US/docs/Web/API/Response
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.