Body mixin 抓取 API represents the body of the response/request, allowing you to declare what its content type is and how it should be handled.

Body is implemented by both Request and 响应 . This provides these objects with an associated body ( stream ), used flag (initially unset), and a MIME 类型 (initially the empty byte sequence).

特性

Body.body 只读
A simple getter used to expose a ReadableStream of the body contents.
Body.bodyUsed 只读
布尔 that indicates whether the body has been read.

方法

Body.arrayBuffer()
Takes a 响应 stream and reads it to completion. It returns a promise that resolves with an ArrayBuffer .
Body.blob()
Takes a 响应 stream and reads it to completion. It returns a promise that resolves with a Blob .
Body.formData()
Takes a 响应 stream and reads it to completion. It returns a promise that resolves with a FormData 对象。
Body.json()
Takes a 响应 stream and reads it to completion. It returns a promise that resolves with the result of parsing the body text as JSON .
Body.text()
Takes a 响应 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 example below uses a simple fetch call to grab an image and display it in an <img> tag. You'll notice that since we are requesting an image, we need to run Body.blob() ( 响应 implements body) to give the response its correct MIME type.

HTML 内容

<img class="my-image" src="https://wikipedia.org/static/images/project-logos/frwiki-1.5x.png">
					

JS Content

const myImage = document.querySelector('.my-image');
fetch('https://upload.wikimedia.org/wikipedia/commons/7/77/Delete_key1.jpg')
	.then(res => res.blob())
	.then(res => {
		const objectURL = URL.createObjectURL(res);
		myImage.src = objectURL;
});
					

规范

规范 状态 注释
Fetch
The definition of 'Body' in that specification.
实时标准

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Body Chrome 42
42
41 Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge ≤18 Firefox 39
39
34 Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No Opera 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari 10 WebView Android 42 Chrome Android 42 Firefox Android ? Opera Android 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari iOS 10 Samsung Internet Android 4.0
arrayBuffer Chrome 42
42
41 Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge ≤18 Firefox 39
39
34 Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No Opera 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari 10 WebView Android No Chrome Android 42 Firefox Android No Opera Android 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari iOS Yes Samsung Internet Android No
blob Chrome 42
42
41 Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge ≤18 Firefox 39
39
34 Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No Opera 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari 10 WebView Android No Chrome Android 42 Firefox Android No Opera Android 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari iOS 10 Samsung Internet Android No
body Chrome 52 Edge ≤18 Firefox 65
65
57 Disabled
Disabled From version 57: this feature is behind the dom.streams.enabled preference (needs to be set to true ) 和 preference (needs to be set to ). To change preferences in Firefox, visit about:config.
IE No Opera 39 Safari 10 WebView Android 52 Chrome Android 52 Firefox Android 65
65
57 Disabled
Disabled From version 57: this feature is behind the dom.streams.enabled preference (needs to be set to true ) 和 preference (needs to be set to ). To change preferences in Firefox, visit about:config.
Opera Android 41 Safari iOS Yes Samsung Internet Android 6.0
bodyUsed Chrome 42
42
41 Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge ≤18 Firefox 39
39
34 Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No Opera 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari No WebView Android No Chrome Android No Firefox Android No Opera Android 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari iOS No Samsung Internet Android No
formData Chrome 60 Edge ≤79 Firefox 39
39
34 Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No Opera 47 Safari 10 WebView Android 60 Chrome Android 60 Firefox Android No Opera Android 44 Safari iOS Yes Samsung Internet Android 8.0
json Chrome 42
42
41 Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge ≤18 Firefox 39
39
34 Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No Opera 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari 10 WebView Android No Chrome Android 42 Firefox Android No Opera Android 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari iOS 10 Samsung Internet Android No
text Chrome 42
42
41 Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge ≤18 Firefox 39
39
34 Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No Opera 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari 10 WebView Android No Chrome Android 42 Firefox Android No Opera Android 29
29
28 Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari iOS 10 Samsung Internet Android No

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改:
  1. Body
  2. 特性
    1. body
    2. bodyUsed
  3. 方法
    1. arrayBuffer()
    2. blob()
    3. formData()
    4. json()
    5. text()
  4. 实现通过:
    1. Request
    2. 响应

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1