Skip to main content

Response

Response 类表示页面接收到的响应。


方法

🌐 Methods

allHeaders

Added in: v1.15 response.allHeaders

包含与此响应关联的所有响应 HTTP 标头的对象。

🌐 An object with all the response HTTP headers associated with this response.

用法

Response.allHeaders();

返回


body

Added before v1.9 response.body

返回带有响应正文的缓冲区。

🌐 Returns the buffer with response body.

用法

Response.body();

返回


finished

Added before v1.9 response.finished

等待此响应完成,总是返回 null

🌐 Waits for this response to finish, returns always null.

用法

Response.finished();

返回


frame

Added before v1.9 response.frame

返回发起此响应的Frame

🌐 Returns the Frame that initiated this response.

用法

Response.frame();

返回


fromServiceWorker

Added in: v1.23 response.fromServiceWorker

指示此响应是否由服务工作者的 Fetch 处理程序处理(即通过 FetchEvent.respondWith)。

🌐 Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via FetchEvent.respondWith).

用法

Response.fromServiceWorker();

返回


headerValue

Added in: v1.15 response.headerValue

返回与名称匹配的头部的值。名称不区分大小写。如果多个头部具有相同的名称(set-cookie 除外),它们将作为列表返回,列表项由 , 分隔。对于 set-cookie,使用 \n 分隔符。如果未找到任何头部,则返回 null

🌐 Returns the value of the header matching the name. The name is case-insensitive. If multiple headers have the same name (except set-cookie), they are returned as a list separated by , . For set-cookie, the \n separator is used. If no headers are found, null is returned.

用法

Response.headerValue(name);

参数

返回


headerValues

Added in: v1.15 response.headerValues

返回所有与名称匹配的头部值,例如 set-cookie。名称不区分大小写。

🌐 Returns all values of the headers matching the name, for example set-cookie. The name is case-insensitive.

用法

Response.headerValues(name);

参数

返回


headers

Added before v1.9 response.headers

一个包含响应 HTTP 头的对象。头名称为小写。请注意,此方法不会返回与安全相关的头,包括与 cookie 相关的头。你可以使用 Response.allHeaders() 获取包含 cookie 信息的完整头列表。

🌐 An object with the response HTTP headers. The header names are lower-cased. Note that this method does not return security-related headers, including cookie-related ones. You can use Response.allHeaders() for complete list of headers that include cookie information.

用法

Response.headers();

返回


headersArray

Added in: v1.15 response.headersArray

一个包含所有与该响应关联的请求HTTP头的数组。与 [Response.allHeaders()](/api/class-response.mdx#response-all-headers) 不同,头部名称不小写。包含多个条目的头部,如“Set-Cookie”,会在数组中多次出现。

🌐 An array with all the request HTTP headers associated with this response. Unlike Response.allHeaders(), header names are NOT lower-cased. Headers with multiple entries, such as Set-Cookie, appear in the array multiple times.

用法

Response.headersArray();

返回


ok

Added before v1.9 response.ok

包含一个布尔值,说明响应是否成功(状态范围为 200-299)。

🌐 Contains a boolean stating whether the response was successful (status in the range 200-299) or not.

用法

Response.ok();

返回


request

Added before v1.9 response.request

返回匹配的 Request 对象。

🌐 Returns the matching Request object.

用法

Response.request();

返回


securityDetails

Added in: v1.13 response.securityDetails

返回 SSL 和其他安全信息。

🌐 Returns SSL and other security information.

用法

Response.securityDetails();

返回

  • null | SecurityDetails#
    • issuer String (optional)

      证书中发行者字段的常用名称组件。此信息仅用于参考。可选。

    • protocol String (optional)

      使用的特定 TLS 协议。(例如 TLS 1.3)。可选。

    • subjectName String (optional)

      证书中主题字段的通用名称组件。此项仅供参考。可选。

    • validFrom double (optional)

      Unix 时间戳(以秒为单位),指定此证书何时生效。可选。

    • validTo double (optional)

      Unix 时间戳(以秒为单位),指定此证书何时失效。可选。


serverAddr

Added in: v1.13 response.serverAddr

返回服务器的 IP 地址和端口。

🌐 Returns the IP address and port of the server.

用法

Response.serverAddr();

返回

  • null | ServerAddr#
    • ipAddress String

      服务器的 IPv4 或 IPV6 地址。

    • port int


status

Added before v1.9 response.status

包含响应的状态代码(例如,200 表示成功)。

🌐 Contains the status code of the response (e.g., 200 for a success).

用法

Response.status();

返回


statusText

Added before v1.9 response.statusText

包含响应的状态文本(例如,通常成功时为“OK”)。

🌐 Contains the status text of the response (e.g. usually an "OK" for a success).

用法

Response.statusText();

返回


text

Added before v1.9 response.text

返回响应正文的文本表示形式。

🌐 Returns the text representation of response body.

用法

Response.text();

返回


url

Added before v1.9 response.url

包含响应的 URL。

🌐 Contains the URL of the response.

用法

Response.url();

返回