Request<TResponse>
Namespace: PuppeteerSharp
public abstract class Request<TResponse> : IRequest where TResponse : IResponseSupports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.
Type parameters
| Name | Description |
|---|---|
TResponse |
Inheritance: object
Implements: IRequest
Derived: BidiHttpRequest, CdpHttpRequest
Properties
Section titled “Properties”FailureText
Section titled “FailureText”public string FailureText { get; }Gets the failure.
Value: string — The failure.
public IFrame Frame { get; }Gets the frame.
Value: IFrame — The frame.
HasPostData
Section titled “HasPostData”public bool HasPostData { get; }True when the request has POST data. Note that PostData might still be null when this flag is true when the data is too long or not readily available in the decoded form. In that case, use FetchPostDataAsync().
Value: bool
Headers
Section titled “Headers”public virtual Dictionary<string, string> Headers { get; protected set; }Gets the HTTP headers.
Value: Dictionary<string, string> — HTTP headers.
public string Id { get; }Gets the request identifier.
Value: string — The request identifier.
Initiator
Section titled “Initiator”public Initiator Initiator { get; }Information about the request initiator.
Value: Initiator
InterceptResolutionState
Section titled “InterceptResolutionState”public abstract InterceptResolutionState InterceptResolutionState { get; }Gets the current intercept resolution state.
Value: InterceptResolutionState
InterceptionId
Section titled “InterceptionId”public string InterceptionId { get; }Gets the interception identifier.
Value: string — The interception identifier.
IsInterceptResolutionHandled
Section titled “IsInterceptResolutionHandled”public abstract bool IsInterceptResolutionHandled { get; protected set; }Gets whether the intercept resolution has already been handled.
Value: bool
IsNavigationRequest
Section titled “IsNavigationRequest”public bool IsNavigationRequest { get; }Gets whether this request is driving frame’s navigation.
Value: bool
Method
Section titled “Method”public HttpMethod Method { get; }Gets the HTTP method.
Value: HttpMethod — HTTP method.
PostData
Section titled “PostData”public string PostData { get; }Gets the post data.
Value: string — The post data.
RedirectChain
Section titled “RedirectChain”public IRequest[] RedirectChain { get; }A redirectChain is a chain of requests initiated to fetch a resource. If there are no redirects and the request was successful, the chain will be empty. If a server responds with at least a single redirect, then the chain will contain all the requests that were redirected. redirectChain is shared between all the requests of the same chain.
Value: IRequest\[\] — The redirect chain.
Example
For example, if the website http://example.com has a single redirect to https://example.com, then the chain will contain one request:
var response = await page.GoToAsync("http://example.com");var chain = response.Request.RedirectChain;Console.WriteLine(chain.Length); // 1Console.WriteLine(chain[0].Url); // 'http://example.com'If the website https://google.com has no redirects, then the chain will be empty:
var response = await page.GoToAsync("https://google.com");var chain = response.Request.RedirectChain;Console.WriteLine(chain.Length); // 0ResourceType
Section titled “ResourceType”public ResourceType ResourceType { get; }Gets the type of the resource.
Value: ResourceType — The type of the resource.
Response
Section titled “Response”public virtual TResponse Response { get; }Value: TResponse
public string Url { get; }Gets the URL.
Value: string — The URL.
Methods
Section titled “Methods”AbortAsync(RequestAbortErrorCode, int?)
Section titled “AbortAsync(RequestAbortErrorCode, int?)”public abstract Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed, int? priority = null)Aborts request. To use this, request interception should be enabled with SetRequestInterceptionAsync(bool). Exception is immediately thrown if the request interception is not enabled.
Parameters
| Name | Type | Description |
|---|---|---|
errorCode |
RequestAbortErrorCode | Optional error code. Defaults to Failed. |
priority |
int? | Optional intercept abort priority. If provided, intercept will be resolved using cooperative handling rules. Otherwise, intercept will be resolved immediately. IMPORTANT: If you set the priority, you will need to attach Request listener using Task%7d) instead of Request. |
Returns: Task — Task.
CanBeIntercepted()
Section titled “CanBeIntercepted()”protected abstract bool CanBeIntercepted()Determines whether this request can be intercepted.
Returns: bool — true if the request can be intercepted; otherwise, false.
ContentAsync()
Section titled “ContentAsync()”public abstract Task<byte[]> ContentAsync()Fetches the unmodified POST data bytes for the request from the browser.
Returns: Task<byte[]> — Task which resolves to the request’s raw POST data, or null when there is none or fetching it fails.
ContinueAsync(Payload, int?)
Section titled “ContinueAsync(Payload, int?)”public abstract Task ContinueAsync(Payload payloadOverrides = null, int? priority = null)Continues request with optional request overrides. To use this, request interception should be enabled with SetRequestInterceptionAsync(bool). Exception is immediately thrown if the request interception is not enabled. If the URL is set it won’t perform a redirect. The request will be silently forwarded to the new url. For example, the address bar will show the original url.
Parameters
| Name | Type | Description |
|---|---|---|
payloadOverrides |
Payload | Optional request overwrites. |
priority |
int? | Optional intercept abort priority. If provided, intercept will be resolved using cooperative handling rules. Otherwise, intercept will be resolved immediately. IMPORTANT: If you set the priority, you will need to attach Request listener using Task%7d) instead of Request. |
Returns: Task — Task.
FetchPostDataAsync()
Section titled “FetchPostDataAsync()”public abstract Task<string> FetchPostDataAsync()Fetches the POST data for the request from the browser.
Returns: Task<string> — Task which resolves to the request’s POST data.
RespondAsync(ResponseData, int?)
Section titled “RespondAsync(ResponseData, int?)”public abstract Task RespondAsync(ResponseData response, int? priority = null)Fulfills request with given response. To use this, request interception should be enabled with SetRequestInterceptionAsync(bool). Exception is thrown if request interception is not enabled.
Parameters
| Name | Type | Description |
|---|---|---|
response |
ResponseData | Response that will fulfill this request. |
priority |
int? | Optional intercept abort priority. If provided, intercept will be resolved using cooperative handling rules. Otherwise, intercept will be resolved immediately. IMPORTANT: If you set the priority, you will need to attach Request listener using Task%7d) instead of Request. |
Returns: Task — Task.
VerifyInterception()
Section titled “VerifyInterception()”protected abstract void VerifyInterception()Verifies that request interception is enabled and the request has not been handled yet.
Exceptions
| Type | Condition |
|---|---|
| PuppeteerException | Thrown when interception is not enabled or request is already handled. |
Made with love by Dario Kondratiuk