HTTP Post and Headers

Overview

You can post form data to the server or add additional headers if necessary. This section covers the following topics:

Calling HtmlToPdfOptions.AddPostData

Setting HtmlToPdfOptions.PostData

Additional Headers

Calling HtmlToPdfOptions.AddPostData

The easiest way to post form data is to call AddPostData to add your form variables. For example, the following code posts several form variables to the server:

//Post address information to an Url to generate an address form
EO.Pdf.HtmlToPdf.Options.AddPostData("addr1", "1234 Abc Road");
EO.Pdf.HtmlToPdf.Options.AddPostData("addr2", "Suite 567");
EO.Pdf.HtmlToPdf.Options.AddPostData("City", "New York City");
EO.Pdf.HtmlToPdf.Options.AddPostData("State", "NY");
EO.Pdf.HtmlToPdf.Options.AddPostData("ZipCode", "33221");
HtmlToPdf.ConvertUrl(url, "c:\\test.pdf");

Setting HtmlToPdfOptions.PostData

You can also set the encoded post data directly through HtmlToPdfOptions's PostData property. When PostData is set, data added through AddPostData are ignored.

Additional Headers

You can set HtmlToPdfOptions's AdditionalHeaders property to send additional headers to the server. The following code sends two additional headers:

//Add additional headers for referer and cookies
EO.Pdf.HtmlToPdf.Options.AdditionalHeaders = new string[]
{
    "Referer: http://www.essentialobjects.com",
    "Accept-Charset: iso-8859-5",
};