草案
此页面不完整。
抓取 API
provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used
XMLHttpRequest
, but it provides a more powerful and flexible feature set. This article explains some of the basic concepts of the Fetch API.
注意: This article will be added to over time. If you find a Fetch concept that you feel needs explaining better, let someone know on the MDN discussion forum ,或 MDN Web Docs room on 矩阵 .
At the heart of Fetch are the Interface abstractions of HTTP
Request
s,
响应
s,
头
,和
Body
payloads, along with a
global fetch
method for initiating asynchronous resource requests. Because the main components of HTTP are abstracted as JavaScript objects, it is easy for other APIs to make use of such functionality.
服务工作者 is an example of an API that makes heavy use of Fetch.
Fetch takes the asynchronous nature of such requests one step further. The API is completely
Promise
-based.
Guard is a feature of
头
objects, with possible values of
immutable
,
request
,
request-no-cors
,
response
,或
none
, depending on where the header is used.
当新
头
object is created using the
Headers()
构造函数
, its guard is set to
none
(the default). When a
Request
or
响应
object is created, it has an associated
头
object whose guard is set as summarized below:
| new object's type | creating constructor |
guard setting of associated
头
对象
|
|---|---|---|
Request
|
Request()
|
request
|
Request()
with
mode
of
no-cors
|
request-no-cors
|
|
响应
|
Response()
|
response
|
error()
or
redirect()
方法
|
immutable
|
A header's guard affects the
set()
,
delete()
,和
append()
methods which change the header's contents. A
TypeError
is thrown if you try to modify a
头
object whose guard is
immutable
. However, the operation will work if
request
and the header
名称
isn't a
forbidden header name
.
request-no-cors
and the header
名称
/
值
是
simple header
.
response
and the header
名称
isn't a
forbidden response header name
.