請求:bytes() 方法

基準線 2025
新推出

自 ⁨2025 年 1 月⁩ 起,此功能在最新的裝置和瀏覽器版本中均可正常工作。此功能可能無法在舊裝置或瀏覽器中工作。

注意:此功能在 Web Workers 中可用。

bytes() 方法是 Request 介面的一部分,它讀取請求體並返回一個 Promise,該 Promise 解析為一個 Uint8Array

語法

js
bytes()

引數

無。

返回值

一個 Promise,它解析為一個 Uint8Array

示例

js
const myArray = new Uint8Array(10);

const request = new Request("/myEndpoint", {
  method: "POST",
  body: myArray,
});

request.bytes().then((buffer) => {
  // do something with the buffer sent in the request
});

規範

規範
Fetch
# dom-body-bytes

瀏覽器相容性

另見