Skip to main content
Version: 22.9.0

HTTPResponse 类

¥HTTPResponse class

HTTPResponse 类表示 类接收到的响应。

¥The HTTPResponse class represents responses which are received by the Page class.

签名:

¥Signature:

export declare abstract class HTTPResponse

备注

¥Remarks

此类的构造函数被标记为内部构造函数。第三方代码不应直接调用构造函数或创建扩展 HTTPResponse 类的子类。

¥The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the HTTPResponse class.

方法

¥Methods

方法

修饰符

描述

buffer()

Promise 解析为带有响应正文的缓冲区。

评论:

浏览器可能会根据 HTTP 标头或其他启发法对缓冲区进行重新编码。如果浏览器无法检测到正确的编码,则缓冲区可能编码不正确。参见 https://github.com/puppeteer/puppeteer/issues/6478

frame()

启动此响应的 框架,如果导航到错误页面,则为 null

fromCache()

如果响应是从浏览器的磁盘缓存或内存缓存提供的,则为 true。

fromServiceWorker()

如果响应是由服务工作进程提供的,则为 true。

headers()

具有与响应关联的 HTTP 标头的对象。所有标头名称均为小写。

json()

Promise 解析为响应正文的 JSON 表示形式。

评论:

如果响应正文无法通过 JSON.parse 进行解析,则此方法将抛出异常。

ok()

如果响应成功(状态范围为 200-299),则为 true。

remoteAddress()

用于连接到远程服务器的 IP 地址和端口号。

request()

匹配的 HTTPRequest 对象。

securityDetails()

如果通过安全连接收到响应,则为 SecurityDetails,否则为 null

status()

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

statusText()

响应的状态文本(例如,通常为 "OK" 表示成功)。

text()

Promise 解析为响应正文的文本 (utf8) 表示形式。

timing()

与响应相关的时间信息。

url()

响应的 URL。