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.

Render a URL with custom HTTP headers in one line!

var pdf = new ChromePdfRenderer { RenderingOptions = { HttpRequestHeaders = new Dictionary<string,string> { { "Authorization", "Bearer your_token_here" }, { "User-Agent", "MyApp/1.0" } } } }
    .RenderUrlAsPdf("https://httpbin.org/bearer")
    .SaveAs("withHeaders.pdf");
Install with NuGet
green arrow pointer

PM >  Install-Package IronPdf

Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer


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");
Imports IronPdf
Imports System.Collections.Generic

Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.HttpRequestHeaders = New Dictionary(Of String, String) From {
	{"Authorization", "Bearer test-token-123"}
}

' Render PDF from authenticated page
Dim pdf = renderer.RenderUrlAsPdf("https://httpbin.org/bearer")
pdf.SaveAs("output.pdf")
$vbLabelText   $csharpLabel

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

Frequently Asked Questions

What is an HTTP request header?

An HTTP request header is a piece of metadata sent by a client to a server when making an HTTP request, providing additional information about the request.

How can I use HTTP request headers in PDF rendering?

In IronPDF, you can use HTTP request headers by preparing them as a C# dictionary and assigning the dictionary to the HttpRequestHeaders property of the HTML to PDF renderer.

What are common HTTP request headers?

Common HTTP request headers include Authorization, Content-Type, Accept, User-Agent, Referer, and Cookie.

How do I download a library for use with HTTP request headers?

You can download IronPDF from NuGet by visiting the package page and following the instructions to include it in your project.

What is the purpose of the Authorization header?

The Authorization header is used to send authentication credentials, such as a Bearer token or Basic auth, to the server.

How do you specify the expected response format in HTTP headers?

The expected response format is specified using the Accept header, where you can define formats like text/html or application/json.

What is an example of using HTTP request headers in PDF rendering?

An example includes creating a dictionary of headers, such as Authorization and Content-Type, assigning them to the HttpRequestHeaders property, and rendering a URL to PDF using the RenderUrlAsPdf method in IronPDF.

Can the rendered PDF be exported in different formats?

Yes, IronPDF can save the rendered PDF as a file or export it as bytes, allowing you to choose the format that fits your needs.

Chaknith related to Common HTTP Request Headers
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.