APIRequest
公开可用于 Web API 测试的 API。此类用于创建 APIRequestContext 实例,该实例可用于发送 Web 请求。可以通过 playwright.request 获取此类的实例。有关更多信息,请参阅 APIRequestContext。
apiRequest.newContext([options])
Added in: v1.16options?<Object>baseURL?<string> 像 apiRequestContext.get(url[, options]) 这样的方法会使用URL()构造函数来构建相应的 URL,并将 base URL 考虑在内。示例:#- baseURL:
http://localhost:3000并发送请求到/bar.html结果为http://localhost:3000/bar.html - baseURL:
http://localhost:3000/foo/并发送请求到./bar.html结果为http://localhost:3000/foo/bar.html - baseURL:
http://localhost:3000/foo(没有尾部斜杠) 并导航到./bar.html结果为http://localhost:3000/bar.html
- baseURL:
extraHTTPHeaders?<Object<string, string>> 包含每个请求都要发送的额外 HTTP 头的对象。#httpCredentials?<Object> HTTP 身份验证的凭据。#ignoreHTTPSErrors?<boolean> 发送网络请求时是否忽略 HTTPS 错误。默认为false。#proxy?<Object> 网络代理设置。#storageState?<string|Object> 使用给定的存储状态填充上下文。此选项可用于使用通过 browserContext.storageState([options]) 或 apiRequestContext.storageState([options]) 获得的已登录信息初始化上下文。可以是保存的存储文件的路径,也可以是 browserContext.storageState([options]) 或 apiRequestContext.storageState([options]) 方法之一返回的值。#timeout?<number> 等待响应的最大时间(毫秒)。默认为30000(30 秒)。传递0可禁用超时。#userAgent?<string> 在此上下文中使用的特定用户代理。#
- returns: <Promise<APIRequestContext>>#
创建新的 APIRequestContext 实例。