Response
Response 类代表页面接收的响应。
¥Response class represents responses which are received by page.
方法
¥Methods
all_headers
Added in: v1.15包含与此响应关联的所有响应 HTTP 标头的对象。
¥An object with all the response HTTP headers associated with this response.
用法
¥Usage
response.all_headers()
返回
¥Returns
body
Added before v1.9返回带有响应正文的缓冲区。
¥Returns the buffer with response body.
用法
¥Usage
response.body()
返回
¥Returns
finished
Added before v1.9等待此响应完成,始终返回 null
。
¥Waits for this response to finish, returns always null
.
用法
¥Usage
response.finished()
返回
¥Returns
header_value
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.
用法
¥Usage
response.header_value(name)
参数
¥Arguments
标头的名称。
¥Name of the header.
返回
¥Returns
header_values
Added in: v1.15返回与名称匹配的标头的所有值,例如 set-cookie
。名称不区分大小写。
¥Returns all values of the headers matching the name, for example set-cookie
. The name is case-insensitive.
用法
¥Usage
response.header_values(name)
参数
¥Arguments
标头的名称。
¥Name of the header.
返回
¥Returns
headers_array
Added in: v1.15包含与此响应关联的所有请求 HTTP 标头的数组。与 response.all_headers() 不同,标头名称不是小写的。具有多个条目的标头(例如 Set-Cookie
)会多次出现在数组中。
¥An array with all the request HTTP headers associated with this response. Unlike response.all_headers(), header names are NOT lower-cased. Headers with multiple entries, such as Set-Cookie
, appear in the array multiple times.
用法
¥Usage
response.headers_array()
返回
¥Returns
标头的名称。
¥Name of the header.
value
str
标头的值。
¥Value of the header.
json
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
.
用法
¥Usage
response.json()
返回
¥Returns
security_details
Added in: v1.13返回 SSL 和其他安全信息。
¥Returns SSL and other security information.
用法
¥Usage
response.security_details()
返回
¥Returns
发行人字段的通用名称组件。从证书中。这应该仅用于提供信息的目的。可选的。
¥Common Name component of the Issuer field. from the certificate. This should only be used for informational purposes. Optional.
protocol
str (optional)
使用的特定 TLS 协议。(例如 TLS 1.3
)。可选的。
¥The specific TLS protocol used. (e.g. TLS 1.3
). Optional.
subjectName
str (optional)
证书中主题字段的通用名称组件。这应该仅用于提供信息的目的。可选的。
¥Common Name component of the Subject field from the certificate. This should only be used for informational purposes. Optional.
validFrom
float (optional)
指定此证书何时生效的 Unix 时间戳(以秒为单位)。可选的。
¥Unix timestamp (in seconds) specifying when this cert becomes valid. Optional.
validTo
float (optional)
指定此证书何时无效的 Unix 时间戳(以秒为单位)。可选的。
¥Unix timestamp (in seconds) specifying when this cert becomes invalid. Optional.
server_addr
Added in: v1.13返回服务器的 IP 地址和端口。
¥Returns the IP address and port of the server.
用法
¥Usage
response.server_addr()
返回
¥Returns
服务器的 IPv4 或 IPV6 地址。
¥IPv4 or IPV6 address of the server.
port
int
text
Added before v1.9返回响应正文的文本表示形式。
¥Returns the text representation of response body.
用法
¥Usage
response.text()
返回
¥Returns
属性
¥Properties
frame
Added before v1.9返回发起此响应的 Frame。
¥Returns the Frame that initiated this response.
用法
¥Usage
response.frame
返回
¥Returns
from_service_worker
Added in: v1.23指示此响应是否由 Service Worker 的 Fetch Handler 完成(即通过 FetchEvent.respondWith)。
¥Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via FetchEvent.respondWith).
用法
¥Usage
response.from_service_worker
返回
¥Returns
headers
Added before v1.9具有响应 HTTP 标头的对象。标头名称是小写的。请注意,此方法不会返回与安全相关的标头,包括与 cookie 相关的标头。你可以使用 response.all_headers() 获取包含 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.all_headers() for complete list of headers that include cookie
information.
用法
¥Usage
response.headers
返回
¥Returns
ok
Added before v1.9包含一个布尔值,说明响应是否成功(状态范围为 200-299)。
¥Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
用法
¥Usage
response.ok
返回
¥Returns
request
Added before v1.9返回匹配的 Request 对象。
¥Returns the matching Request object.
用法
¥Usage
response.request
返回
¥Returns
status
Added before v1.9包含响应的状态代码(例如,200 表示成功)。
¥Contains the status code of the response (e.g., 200 for a success).
用法
¥Usage
response.status
返回
¥Returns
status_text
Added before v1.9包含响应的状态文本(例如,通常 "OK" 表示成功)。
¥Contains the status text of the response (e.g. usually an "OK" for a success).
用法
¥Usage
response.status_text
返回
¥Returns
url
Added before v1.9包含响应的 URL。
¥Contains the URL of the response.
用法
¥Usage
response.url
返回
¥Returns