Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.








Sys.Net.WebRequest headers Property

Gets the HTTP headers for the Sys.Net.WebRequest instance.


var headers = MyWebRequest.get_headers();

Return Value

A dictionary of name/value pairs that contains the HTTP headers that are sent with the Web request.


The headers property method returns a dictionary that you can use to set custom headers. If there are no custom headers currently associated with the Web request, an empty dictionary is returned. You can use the returned dictionary to set your custom header values.


The following example shows how to use the HTTP headers. This code is part of a complete example found in the WebRequest class overview.


// This function sets an HTTP header for
// the Web request.
 function WebRequestHeader() 
    // Instantiate the WebRequest object.
    var wRequest =  new Sys.Net.WebRequest();

    // Set the request Url.  

    // Set the request verb.

    var body = "Message=Hello! Do you hear me?"

    // Set the value of the HTTP header's "Content-Length".
    wRequest.get_headers()["Content-Length"] = body.length;

    // Set the web request completed event handler,
    // for processing return data.

    // Clear the results page element.
    GetElementById("ResultsId").innerHTML = "";

    // Execute the request.