October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk7 min

How to Use a Screenshot API with C# and .NET

A practical guide to capturing remote webpages from C# and .NET with a hosted screenshot API, including HttpClient code, credentials, response handling, options, and errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture a remote webpage with C#, send its URL and capture options to a hosted screenshot API over HTTP, then handle the response according to that provider’s contract. Keep the API key on the server, check for errors before saving bytes, and do not assume every provider returns an image file. This is different from capturing the current screen of a .NET MAUI app.

What a screenshot API does—and what it does not

A hosted screenshot API renders a webpage from a URL and returns an image, PDF, or response containing a link or metadata. Your .NET application supplies the request and consumes the provider’s documented response; the remote service performs the browser rendering.

As an Amazon Associate I earn from qualifying purchases.

This is not the .NET MAUI Screenshot API. Microsoft describes that API as capturing “the current displayed screen of the app.” It uses CaptureAsync() and exposes IsCaptureSupported for platform support. It is for an app’s own visible UI, not for rendering an arbitrary webpage URL. See Microsoft Learn’s Screenshot class documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose and confirm the provider contract first

Before writing the request, check the chosen service’s current documentation. Endpoint, HTTP method, authentication, parameter names, supported options, and response format are provider-specific. One API may return image bytes directly; another may return JSON or redirect to an image or PDF.

  • Endpoint and method: Confirm the URL and whether the operation uses GET, POST, or both.
  • Authentication: Use the exact header or credential mechanism the provider documents.
  • Inputs: Confirm how to pass the target URL, output format, viewport and other capture settings.
  • Response: Determine whether to save binary content, parse JSON, or follow a returned URL or redirect.
  • Failures and limits: Check documented error responses, rate limits, quota behavior, and timeout guidance.

For example, ScreenshotAPI.to documents a GET request that returns image bytes, uses an x-api-key header, and provides a dependency-free HttpClient example for .NET 6+. Its guide says it has no official .NET SDK. Screenshot API documents a different REST contract: it describes GET and POST, says GET returns JSON by default, and documents a redirect option to an image or PDF. Its documentation also describes bearer authorization and an X-API-Key header. These details are not interchangeable; use the contract for the service you actually call. See ScreenshotAPI.to’s C# / .NET guide and Screenshot API’s REST documentation.

Make a binary screenshot request with HttpClient

The following complete console example follows ScreenshotAPI.to’s documented GET-and-image-bytes pattern. It expects a SCREENSHOTAPI_KEY environment variable, requests a PNG, checks the HTTP status, and writes the response bytes to a file. Confirm the provider’s current endpoint, parameter names, authentication, and format options before using this pattern with another service.

using System.Net.Http.Headers;

var apiKey = Environment.GetEnvironmentVariable("SCREENSHOTAPI_KEY");
if (string.IsNullOrWhiteSpace(apiKey))
{
    throw new InvalidOperationException("Set the SCREENSHOTAPI_KEY environment variable.");
}

var targetUrl = "https://example.com";
var endpoint = "https://screenshotapi.to/api/v1/screenshot";
var requestUrl = $"{endpoint}?url={Uri.EscapeDataString(targetUrl)}&output=png";

using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(90) };
using var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.Add("x-api-key", apiKey);

using var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();

var imageBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("screenshot.png", imageBytes);

Console.WriteLine($"Saved screenshot.png ({imageBytes.Length} bytes)");

The header and endpoint above are ScreenshotAPI.to-specific. Its guide documents the API key in x-api-key, the URL query parameter, a success-status check, reading the response as bytes, and saving them with File.WriteAllBytesAsync. The output=png setting and the exact options supported should be verified against the provider’s current documentation. See ScreenshotAPI.to’s C# / .NET guide.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep the API key out of source and browser code

Set the key through environment configuration or your application’s secret-management system. Do not commit a production key, embed it in a browser-delivered page, or expose it in a URL. Screenshot API’s REST documentation recommends authentication headers over query-string authentication; credentials in a URL may be recorded in logs or exposed to recipients. Follow the selected provider’s required header name.

Encode input and handle the actual response

Do not concatenate an unescaped target URL into a query string: characters such as & can change how the request is parsed. Use URI escaping for individual values or a query-building library. If the provider requires complex settings in a JSON POST body, use its documented request model instead of translating the GET example by guesswork.

Check the status before writing a file. For a binary endpoint, read the body as bytes and choose a filename extension consistent with the requested format and response content type. For a JSON endpoint, deserialize the documented response and follow its image URL or redirect behavior as specified; saving JSON as .png will not create an image.

Set capture options deliberately

Capture options affect what the renderer returns, but support and parameter names vary by API. Screenshot API’s REST reference documents options including full-page capture, output format, viewport dimensions, device scale, wait strategy, CSS selector, and delay. Some advanced settings may require POST. Confirm each option in the selected provider’s documentation rather than assuming a setting supported by one service works on another.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Viewport and device scale: Specify dimensions and scale when layout or output resolution matters.
  • Full page: Request it when the output should extend beyond the initially visible viewport.
  • Wait behavior: Use the provider’s supported selector, delay, or wait strategy when content renders asynchronously.
  • Format: Choose a supported image or PDF format and match the saved file handling to the response.
  • Element capture: If supported, use a CSS selector for a particular region and account for the provider’s documented missing-selector behavior.

Use HttpClient appropriately in a .NET application

A short-lived console sample can create one HttpClient for the operation. In a long-running service or ASP.NET application, use the application’s established managed and reused client pattern rather than creating a new client for every screenshot. Configure timeout, cancellation, proxy, and transport behavior to suit the application and provider. If using an SDK, follow its supported client-injection pattern.

Screenshot Scout’s .NET SDK repository specifies .NET 8 or later and installation with dotnet add package ScreenshotScout. It documents accepting a caller-owned HttpClient for custom handlers, proxies, and transport timeout, and distinguishes API exceptions from transport exceptions. This is a separate option from a direct REST call, and its package/runtime requirements should be checked before adoption. See Screenshot Scout’s .NET SDK repository.

Handle common failures

Error codes and response bodies are defined by each provider, not by a universal screenshot API standard. Log enough detail to diagnose a failed request without logging secrets, and map the provider’s documented errors to useful application behavior.

Symptom Possible cause What to check
Unauthorized response Missing, invalid, or incorrectly named credential header Confirm the key is present in server configuration and the header name matches the selected provider’s docs.
Invalid request Malformed target URL, unsupported option, or incorrect parameter/body shape Encode query values and compare the method, names, and request format with the provider’s current reference.
Rate-limit or quota response Provider-specific rate or usage limit reached Inspect the provider’s error response and quota documentation; apply suitable backoff or reduce request volume.
Render failure or timeout The page did not render within the provider’s conditions, or the network request exceeded its timeout Check the target URL, provider status/error details, wait options, and timeout configuration.
Missing-selector error A requested CSS selector did not appear on the page Verify the selector against the rendered page and use the provider’s documented selector-wait behavior.
Saved file is not an image The endpoint returned JSON, an error body, or a redirect rather than image bytes Check status, content type, and response contract before writing the body with an image extension.

Screenshot API’s REST documentation lists unauthorized, invalid-request, rate-limit or quota, render-failure, and missing-selector cases. Screenshot Scout documents API and transport exceptions with response details. Treat those as the contracts of those providers, not as guaranteed statuses or exception types for every service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup:

ScreenshotNeo turns a URL into a screenshot with one GET request. It returns PNG, JPEG, WebP, or PDF, and its parameter names also work with those used by other screenshot APIs, which can make switching easier. The API key and URL go in the request; check its documentation for the exact response and options. See the ScreenshotNeo API documentation.

using System.Net.Http;

var apiKey = Environment.GetEnvironmentVariable("SCREENSHOTNEO_API_KEY");
if (string.IsNullOrWhiteSpace(apiKey))
{
    throw new InvalidOperationException("Set the SCREENSHOTNEO_API_KEY environment variable.");
}

using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(90) };
using var response = await client.GetAsync(
    "https://api.screenshotneo.com/v1/shot?access_key=" + Uri.EscapeDataString(apiKey) +
    "&url=" + Uri.EscapeDataString("https://example.com"));
response.EnsureSuccessStatusCode();
var bytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("shot.webp", bytes);

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Can a screenshot API capture a page that requires authentication?

That depends on the provider’s supported request options and the target site’s access controls. Check whether the API accepts cookies or authorization headers, and do not send credentials unless you trust the provider and have permission to access the page.

Can I return a screenshot from an ASP.NET endpoint instead of saving a file?

Yes. After validating the provider response, return the image bytes from your server response with a content type that matches the actual output format. Keep the screenshot API key on the server rather than exposing it to the browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.