Response
Response 类表示页面接收到的响应。
方法
🌐 Methods
AllHeadersAsync
Added in: v1.15包含与此响应关联的所有响应 HTTP 标头的对象。
🌐 An object with all the response HTTP headers associated with this response.
用法
await Response.AllHeadersAsync();
返回
BodyAsync
Added before v1.9返回带有响应正文的缓冲区。
🌐 Returns the buffer with response body.
用法
await Response.BodyAsync();
返回
FinishedAsync
Added before v1.9等待此响应完成,总是返回 null。
🌐 Waits for this response to finish, returns always null.
用法
await Response.FinishedAsync();
返回
Frame
Added before v1.9返回发起此响应的Frame。
🌐 Returns the Frame that initiated this response.
用法
Response.Frame
返回
FromServiceWorker
Added in: v1.23指示此响应是否由服务工作者的 Fetch 处理程序处理(即通过 FetchEvent.respondWith)。
🌐 Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via FetchEvent.respondWith).
用法
Response.FromServiceWorker
返回
HeaderValueAsync
Added in: v1.15返回与名称匹配的头部的值。名称不区分大小写。如果多个头部具有相同的名称(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.
用法
await Response.HeaderValueAsync(name);
参数
返回
HeaderValuesAsync
Added in: v1.15返回所有与名称匹配的头部值,例如 set-cookie。名称不区分大小写。
🌐 Returns all values of the headers matching the name, for example set-cookie. The name is case-insensitive.
用法
await Response.HeaderValuesAsync(name);
参数
返回
Headers
Added before v1.9一个包含响应 HTTP 头的对象。头名称为小写。请注意,该方法不会返回与安全相关的头信息,包括与 Cookie 相关的头信息。你可以使用 Response.AllHeadersAsync() 获取包含 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.AllHeadersAsync() for complete list of headers that include cookie information.
用法
Response.Headers
返回
HeadersArrayAsync
Added in: v1.15一个包含与此响应相关的所有请求 HTTP 头的数组。与 Response.AllHeadersAsync() 不同,头名称不会被转换为小写。具有多个条目的头,例如 Set-Cookie,会在数组中出现多次。
🌐 An array with all the request HTTP headers associated with this response. Unlike Response.AllHeadersAsync(), header names are NOT lower-cased. Headers with multiple entries, such as Set-Cookie, appear in the array multiple times.
用法
await Response.HeadersArrayAsync();
返回
- IReadOnlyList<
HttpHeader>#
JsonAsync
Added before v1.9返回响应正文的 JSON 表示形式。
🌐 Returns the JSON representation of response body.
如果响应正文无法通过 JSON.parse 解析,该方法将抛出异常。
🌐 This method will throw if the response body is not parsable via JSON.parse.
用法
await Response.JsonAsync();
返回
Ok
Added before v1.9包含一个布尔值,说明响应是否成功(状态范围为 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返回匹配的 Request 对象。
🌐 Returns the matching Request object.
用法
Response.Request
返回
SecurityDetailsAsync
Added in: v1.13返回 SSL 和其他安全信息。
🌐 Returns SSL and other security information.
用法
await Response.SecurityDetailsAsync();
返回
- 安全详细信息?#
ServerAddrAsync
Added in: v1.13返回服务器的 IP 地址和端口。
🌐 Returns the IP address and port of the server.
用法
await Response.ServerAddrAsync();
返回
Status
Added before v1.9包含响应的状态代码(例如,200 表示成功)。
🌐 Contains the status code of the response (e.g., 200 for a success).
用法
Response.Status
返回
StatusText
Added before v1.9包含响应的状态文本(例如,通常成功时为“OK”)。
🌐 Contains the status text of the response (e.g. usually an "OK" for a success).
用法
Response.StatusText
返回
TextAsync
Added before v1.9返回响应正文的文本表示形式。
🌐 Returns the text representation of response body.
用法
await Response.TextAsync();
返回
Url
Added before v1.9包含响应的 URL。
🌐 Contains the URL of the response.
用法
Response.Url
返回