How to use HTTP Request Header
An HTTP request header is a piece of metadata sent by a client (such as a web browser or API client) to a server when making an HTTP request. Headers provide additional information about the request, such as authentication details, content type, user agent, and more.
This feature is used when rendering a URL to PDF, allowing you to provide HTTP header information when making the request.
Get started with IronPDF
Start using IronPDF in your project today with a free trial.
How to use HTTP Request Header
- Download IronPDF from NuGet
- Prepare the HTTP request headers as a C# dictionary
- Assign the dictionary to the HttpRequestHeaders property
- Render the URL to PDF using the
RenderUrlAsPdf
method - Save the PDF as a file or export it as bytes
Use HTTP Request Header Example
Before using the HttpRequestHeaders property to set an HTTP request header, first design a proper HTTP request header object. During the rendering process, this header will be included in the URL request sent to the server. As an example, we will use httpbin.org, a website that helps show the headers request.
:path=/static-assets/pdf/content-code-examples/how-to/http-request-header.cs
using IronPdf;
using System.Collections.Generic;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HttpRequestHeaders = new Dictionary<string, string>
{
{ "Authorization", "Bearer test-token-123" }
};
// Render PDF from authenticated page
var pdf = renderer.RenderUrlAsPdf("https://httpbin.org/bearer");
pdf.SaveAs("output.pdf");
Common HTTP Request Headers
- Authorization: Sends authentication credentials (Bearer token, Basic auth, etc.)
- Content-Type: Defines the format of the request body (e.g., application/json)
- Accept: Specifies the expected response format (e.g., text/html, application/json)
- User-Agent: Identifies the client making the request (browser, API client, etc.)
- Referer: Indicates the page that linked to the current request
- Cookie: Sends cookies for session tracking