Partager via


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.

Remarks

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.

Example

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.  
    wRequest.set_url(postPage); 

    // Set the request verb.
    wRequest.set_httpVerb("POST");

    var body = "Message=Hello! Do you hear me?"
    wRequest.set_body(body);

    // 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.
    wRequest.add_completed(OnWebRequestCompletedHeader);

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

    // Execute the request.
    wRequest.invoke();  
}

See Also

Reference

Sys.Net.WebRequestManager Class

Sys.Net.WebRequestExecutor Class

Sys.Net.XMLHttpExecutor Class