Network & File Transfers

Fetch

Runs the request in the page rather than from outside it, so it goes out with the cookies, TLS fingerprint, header order, and any anti-bot clearance the browser already holds. A relative url resolves against wherever the browser currently is. Mandatory parameter: url. Optional: method (GET when unsaid), body, contentType, headers (flattened to name, value, name, value), and bytes (text unless bytes were asked for). Answers with the response body, or null when the fetch could not be made.

NOTE

This is the endpoint behind the browser-level Fetch, which is what a workflow normally calls. Reach for the endpoint directly when you want one request without the surrounding chain.

Examples

GPAL Fluent: High-level fluent C# API

//Fetch takes a GPALRequest, and there are two ways to have one. Build it, as above, when you know the url and the shape of the call. Capture it with CaptureCallTemplate when the page already makes the call and you would rather not restate its headers and body. Either way the request goes out from inside the page, and SaveTo hands back the response body. This is also the call that honors WithPages and WithTokensFrom, so one request can walk a paged API.

// the request, named the same way the other subsystems name one: url, verb, parameters

GPALRequest search = (GPALRequest)GPAL.Request

.WithPath("/api/search")

.WithHttpMethod(HttpVerb.Get)

.WithParameter("page=1")

.WithName("search");


// run it from inside the page and take the body back

browser.Fetch(search).SaveTo(ref json);


// a call the page made itself can stand in for the hand-built one, which is what CaptureCallTemplate is for

browser.WithCallFilter(endpoint).CaptureCallTemplate(out GPALRequest captured);

MagicHelper: MagicHelper utility library

//The optional arguments are method, body, contentType, headers, and asBytes, in that order.

string json = browser.MagicHelper.Fetch("/api/search?page=1");

Puppeteer Client: Puppeteer-style C# client

browser.PuppeteerClient.Fetch(string url).Execute();

Puppeteer Communicator: Low-level communicator

await browser.PuppeteerCommunicator.Fetch(string url, string method, string body, string contentType, string[] headers, bool asBytes, string sessionId);

REST Client: Direct REST/HTTP client

browser.OttoMagicClient.WithEndpoint(ApiEndpoint.Fetch).WithUrl(string url).Execute();

💬 Ask GPAL