Class Request<TResponse>
- Namespace
- PuppeteerSharp
- Assembly
- PuppeteerSharp.dll
Supports 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.
public abstract class Request<TResponse> : IRequest where TResponse : IResponse
Type Parameters
TResponse
- Inheritance
-
Request<TResponse>
- Implements
- Derived
Properties
FailureText
Gets the failure.
public string FailureText { get; }
Property Value
- string
The failure.
Frame
Gets the frame.
public IFrame Frame { get; }
Property Value
- IFrame
The frame.
HasPostData
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().
public bool HasPostData { get; }
Property Value
Headers
Gets the HTTP headers.
public Dictionary<string, string> Headers { get; }
Property Value
- Dictionary<string, string>
HTTP headers.
Id
Gets the request identifier.
public string Id { get; }
Property Value
- string
The request identifier.
Initiator
Information about the request initiator.
public Initiator Initiator { get; }
Property Value
InterceptionId
Gets the interception identifier.
public string InterceptionId { get; }
Property Value
- string
The interception identifier.
IsNavigationRequest
Gets whether this request is driving frame's navigation.
public bool IsNavigationRequest { get; }
Property Value
Method
Gets the HTTP method.
public HttpMethod Method { get; }
Property Value
- HttpMethod
HTTP method.
PostData
Gets the post data.
public string PostData { get; }
Property Value
- string
The post data.
RedirectChain
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.
public IRequest[] RedirectChain { get; }
Property Value
- IRequest[]
The redirect chain.
Examples
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); // 1
Console.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); // 0
ResourceType
Gets the type of the resource.
public ResourceType ResourceType { get; }
Property Value
- ResourceType
The type of the resource.
Response
public virtual TResponse Response { get; }
Property Value
- TResponse
Url
Gets the URL.
public string Url { get; }
Property Value
- string
The URL.
Methods
AbortAsync(RequestAbortErrorCode, int?)
Aborts request. To use this, request interception should be enabled with SetRequestInterceptionAsync(bool). Exception is immediately thrown if the request interception is not enabled.
public abstract Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed, int? priority = null)
Parameters
errorCode
RequestAbortErrorCodeOptional 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 AddRequestInterceptor(Func<IRequest, Task>) instead of Request.
Returns
- Task
Task.
ContinueAsync(Payload, int?)
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.
public abstract Task ContinueAsync(Payload payloadOverrides = null, int? priority = null)
Parameters
payloadOverrides
PayloadOptional 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 AddRequestInterceptor(Func<IRequest, Task>) instead of Request.
Returns
- Task
Task.
FetchPostDataAsync()
Fetches the POST data for the request from the browser.
public abstract Task<string> FetchPostDataAsync()
Returns
RespondAsync(ResponseData, int?)
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.
public abstract Task RespondAsync(ResponseData response, int? priority = null)
Parameters
response
ResponseDataResponse 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 AddRequestInterceptor(Func<IRequest, Task>) instead of Request.
Returns
- Task
Task.