Sys.Net.WebRequest body Property
Gets or sets the HTTP body of the Sys.Net.WebRequest instance.
var body = MyWebRequest.get_body();
MyWebRequest.set_body(value);
Parameters
Parameter |
Description |
---|---|
value |
The HTTP body to assign to the Web request. |
Return Value
The HTTP body of the Web request. If the body of the HTTP request has not been previously set or has been set to null, null is returned.
Remarks
Use this property to get or set the body of the HTTP request. The value parameter must be a string, null, or a reference to an XmlDocument object (such as XMLDOM). For more information, see XMLDocument Property on the MSDN Web site.
Example
The following example shows how to set the HTTP request body. This code is part of a complete example found in the Sys.Net.WebRequest class overview.
// This function performs a POST Web request
// to upload information to the resource
// identified by the Url.
function PostWebRequest()
{
// 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);
wRequest.get_headers()["Content-Length"] = body.length;
// Set the web request completed event handler,
// for processing return data.
wRequest.add_completed(OnWebRequestCompleted);
// Clear the results page element.
GetElementById("ResultsId").innerHTML = "";
// Execute the request.
wRequest.invoke();
}
See Also
Reference
Sys.Net.WebRequestManager Class