Sys.Net.WebRequest body 属性

更新:2007 年 11 月

获取或设置 Sys.Net.WebRequest 实例的 HTTP 正文。

var body = MyWebRequest.get_body();
MyWebRequest.set_body(value);

参数

参数

说明

value

分配给 Web 请求的 HTTP 正文。

返回值

Web 请求的 HTTP 正文。如果尚未设置 HTTP 请求的正文,或者该正文已设置为 null,则返回 null。

备注

使用此属性可以获取或设置 HTTP 请求的正文。value 参数必须是字符串、null 或对 XmlDocument 对象的引用(例如 XMLDOM)。有关更多信息,请参见 MSDN 网站上的 XMLDocument 属性(可能为英文网页)。

示例

下面的示例演示如何设置 HTTP 请求正文。此代码摘自 Sys.Net.WebRequest 类概述中的一个完整示例。

// 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();  

}

请参见

参考

Sys.Net.WebRequestManager 类

Sys.Net.WebRequestExecutor 类

Sys.Net.XMLHttpExecutor 类