首页 > 代码库 > WebRequestManager对象的使用

WebRequestManager对象的使用

WebRequestManager可以喝WebRequest对象一起使用。

WebRequestManager对象的add_completedRequest方法,可以用来处理所有WebRequest对象的请求程序。

Time.aspx

<%@ Page Language="C#" %><script runat="server">    protected override void onl oad(EventArgs e)    {        base.OnLoad(e);        Response.Write(DateTime.Now.ToUniversalTime());    }</script>

GlobalCompleted.aspx

<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>Networking</title>    <script type="text/javascript">        function pageLoad() {            Sys.Net.WebRequestManager.add_completedRequest(completedHandler);            var webRequest = new Sys.Net.WebRequest();            webRequest.set_url("Time.aspx");            var webRequest2 = new Sys.Net.WebRequest();            webRequest2.set_url(TimedSleep.aspx);            Sys.Net.WebRequestManager.executeRequest(webRequest2);            Sys.Net.WebRequestManager.executeRequest(webRequest);        }        function completedHandler(executor) {            if (executor.get_responseAvailable()) {                $get(placeholder).innerHTML += "<br />" +                    executor.get_webRequest().get_url() +                    " returned " +                    executor.get_responseData();             }        }    </script></head><body>    <form id="form1" runat="server">    <div>        <asp:ScriptManager ID="ScriptManager1" runat="server">        </asp:ScriptManager>        <div id="placeholder">processing request</div>    </div>    </form></body></html>

 

WebRequestManager对象的使用