Type Default Value Read Only Description
[C#]
string

[Visual Basic]
String
"" No Additional HTTP headers to send in the request.

 

   

Notes
 

This property specifies HTTP headers added to the default headers. It must follow the syntax of HTTP headers.

For example, you may add the cookies from a response to a request under some authentication (e.g. ASP.NET Forms) where a session ID is returned for subsequent requests so re-authentication is not needed. See the NoCookie property for further information if you specify cookies in the HTTP headers.

 

   

Example
 

The following example shows how this property may be used.

[C#]
Doc doc = new Doc();
string url = ...;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer(); // required for HttpWebResponse.Cookies
request.Credentials = ...;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if(response.Cookies.Count>0) { // includes ASP.NET_SessionId
  bool needsCookie2 = false;
  StringBuilder builder = new StringBuilder("Cookie: ");
  for(int i = 0; i<response.Cookies.Count; ++i) {
    Cookie cookie = response.Cookies[i];
    if(!needsCookie2 && cookie.Version!=1)
      needsCookie2 = true;
    if(i>0)
      builder.Append("; ");
    builder.Append(cookie.ToString());
  }
  builder.Append(!needsCookie2? "\r\n": "\r\nCookie2: $Version=1\r\n");
  doc.HtmlOptions.HttpAdditionalHeaders = builder.ToString();
}
doc.HtmlOptions.NoCookie = true;
doc.HtmlOptions.HostWebBrowser = false;
// cookieless Forms Authentication adds authentication ticket to the URL
int id = doc.AddImageUrl(response.ResponseUri.AbsoluteUri);
doc.Save(Server.MapPath("HttpHeaders.pdf"));
doc.Clear();

[Visual Basic]
Dim doc As Doc = New Doc()
Dim url As String = ...
Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
request.CookieContainer = New CookieContainer() ' required for HttpWebResponse.Cookies
request.Credentials = ...
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
If response.Cookies.Count > 0 Then ' includes ASP.NET_SessionId
  Dim needsCookie2 As Boolean = False
  Dim builder As StringBuilder = New StringBuilder("Cookie: ")
  For i As Integer = 0 To response.Cookies.Count - 1
    Dim cookie As Cookie = response.Cookies(i)
    If Not needsCookie2 AndAlso cookie.Version <> 1 Then
      needsCookie2 = True
    End If
    If i > 0 Then builder.Append("; ")
    builder.Append(cookie.ToString())
  Next
  If Not needsCookie2 Then
    builder.Append(ControlChars.CrLf)
  Else
    builder.Append(ControlChars.CrLf & "Cookie2: $Version=1" & ControlChars.CrLf)
  End If
  doc.HtmlOptions.HttpAdditionalHeaders = builder.ToString()
End If
doc.HtmlOptions.NoCookie = True
doc.HtmlOptions.HostWebBrowser = False
' cookieless Forms Authentication adds authentication ticket to the URL
Dim id As Integer = doc.AddImageUrl(response.ResponseUri.AbsoluteUri)
doc.Save(Server.MapPath("HttpHeaders.pdf"))
doc.Clear()

ASP.NET_SessionId. If your application runs in ASP.NET, you cannot use the cookie from the application's originating request as it identifies the session. If the site containing the target HTML page is different from your site, the session ID is invalid. If it is the same, this will cause a re-entrance in the same session, and ASP.NET does not allow re-entrance for the same session.