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.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet

    PM > Install-Package IronPdf

  2. Copy the code

    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");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

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

How can I render a URL to PDF with HTTP request headers in C#?

You can render a URL to PDF with HTTP request headers in C# using IronPDF by setting the HttpRequestHeaders property of the ChromePdfRenderer class. First, prepare your HTTP headers as a C# dictionary and then use the RenderUrlAsPdf method to convert the URL to PDF.

What is the role of the Authorization header in HTTP requests?

The Authorization header is used to send authentication credentials, such as a Bearer token or Basic auth, to the server. When rendering a URL to PDF with IronPDF, you can include this header in the HttpRequestHeaders dictionary to ensure authenticated requests.

How do I specify custom HTTP headers when converting HTML to PDF?

To specify custom HTTP headers when converting HTML to PDF in IronPDF, create a dictionary with your desired headers and assign it to the HttpRequestHeaders property of the PDF renderer. Then use RenderUrlAsPdf to render the URL.

Which common HTTP request headers can be used in PDF rendering?

Common HTTP request headers that can be used in PDF rendering include Authorization, Content-Type, Accept, User-Agent, Referer, and Cookie. In IronPDF, these can be set in the HttpRequestHeaders dictionary to customize the HTTP request.

Can I test HTTP request headers with a real server?

Yes, you can test HTTP request headers with a real server like httpbin.org, which can display the headers received. This is useful when rendering PDFs with IronPDF to verify that your headers are correctly included in the request.

How do you manage authentication tokens in HTTP headers for PDF rendering?

Authentication tokens can be managed in HTTP headers by including them in the Authorization header within the HttpRequestHeaders dictionary when using IronPDF. This ensures secure and authenticated requests during PDF rendering.

Is it possible to export the rendered PDF in different formats?

Yes, with IronPDF, you can save the rendered PDF as a file or export it as bytes, which allows for flexibility in choosing the format that best fits your application’s needs.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.