刚喝了一口咖啡,真苦!
就像生活一样,连心都是苦的。虽然有人说咖啡很不错,可那只是对于适合他的人来说。
在一个地方呆久了,心里也会像咖啡一样苦。
把我今天上午学习的结果粘出来。
aspx页:(其cs页面无任何代码)
Handler.ashx页:
就像生活一样,连心都是苦的。虽然有人说咖啡很不错,可那只是对于适合他的人来说。
在一个地方呆久了,心里也会像咖啡一样苦。
把我今天上午学习的结果粘出来。
aspx页:(其cs页面无任何代码)
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sys_WebRequest.aspx.cs" Inherits="Sys_WebRequest" %>
2![](/Images/OutliningIndicators/None.gif)
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4![](/Images/OutliningIndicators/None.gif)
5
<html xmlns="http://www.w3.org/1999/xhtml" >
6
<head runat="server">
7
<title>无标题页</title>
8
</head>
9
<body>
10
<form id="form1" runat="server">
11
<div>
12
<asp:ScriptManager ID="ScriptManager1" runat="server">
13
</asp:ScriptManager>
14
15
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
16
<ContentTemplate>
17
<%=DateTime.Now %>
18
<br />
19
<asp:TextBox TextMode="multiLine" ID="txtContent" Rows="5" Columns="4" runat="server" />
20
<asp:Button ID="Button1" runat="server" Text="Refresh" />
21
</ContentTemplate>
22
</asp:UpdatePanel>
23
24
<input type="button" onclick="sendRequest('normal');" value="Normal" />
25
<input type="button" onclick="sendRequest('error');" value="Error" />
26
<input type="button" onclick="sendRequest('timeout');" value="TimeOut" />
27
<input type="button" onclick="try{webRequest.get_executor().abort();}catch(e){alert(e.message+'\n请先单击timeout按钮,并在3秒钟内单击此按钮');}" value="abort" />
28
29
<script type="text/javascript" language="javascript">
30
31
var webRequest;
32
function sendRequest(action)
33
{
34
webRequest = new Sys.Net.WebRequest();
35
webRequest.set_url("handlers/handler.ashx");
36
37
//设置头信息
38
webRequest.get_headers()["action"]=action;
39
40
//设置body信息
41
webRequest.set_body("data=" + encodeURIComponent($get("txtContent").innerHTML));
42
webRequest.set_httpVerb("POST");
43
webRequest.set_timeout(3000);
44
45
webRequest.add_completed(OnCompleted);
46
webRequest.invoke();
47
}
48
49
function OnCompleted(executor,e)
50
{
51
if(executor.get_aborted())
52
{
53
alert("Request Aborted!");
54
}
55
else if(executor.get_responseAvailable())
56
{
57
var statusCode=executor.get_statusCode();
58
alert("statusCode=" + statusCode);
59
if(statusCode < 200|| statusCode >= 300)
60
{
61
alert("Error Occured!");
62
}
63
else
64
{
65
alert(executor.get_responseData());
66
}
67
}
68
else if(executor.get_timedOut())
69
{
70
alert("Time Out!");
71
}
72
else
73
{
74
alert("error occured!");
75
}
76
}
77
78
function pageLoad()
79
{
80
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(OnRequestEnd);
81
}
82
function OnRequestEnd(sender,e)
83
{
84
if(e.get_error())
85
{
86
e.set_errorHandled(true);
87
alert(e.get_error().message);
88
}
89
else if(e.get_response().get_aborted())
90
{
91
}
92
}
93
</script>
94
</div>
95
</form>
96
</body>
97
</html>
98![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/None.gif)
18
![](/Images/OutliningIndicators/None.gif)
19
![](/Images/OutliningIndicators/None.gif)
20
![](/Images/OutliningIndicators/None.gif)
21
![](/Images/OutliningIndicators/None.gif)
22
![](/Images/OutliningIndicators/None.gif)
23
![](/Images/OutliningIndicators/None.gif)
24
![](/Images/OutliningIndicators/None.gif)
25
![](/Images/OutliningIndicators/None.gif)
26
![](/Images/OutliningIndicators/None.gif)
27
![](/Images/OutliningIndicators/None.gif)
28
![](/Images/OutliningIndicators/None.gif)
29
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/InBlock.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/InBlock.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/InBlock.gif)
50
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
51
![](/Images/OutliningIndicators/InBlock.gif)
52
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/InBlock.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
61
![](/Images/OutliningIndicators/InBlock.gif)
62
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
63
![](/Images/OutliningIndicators/InBlock.gif)
64
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
65
![](/Images/OutliningIndicators/InBlock.gif)
66
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
67
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
68
![](/Images/OutliningIndicators/InBlock.gif)
69
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
70
![](/Images/OutliningIndicators/InBlock.gif)
71
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
72
![](/Images/OutliningIndicators/InBlock.gif)
73
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
74
![](/Images/OutliningIndicators/InBlock.gif)
75
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
76
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
77
![](/Images/OutliningIndicators/InBlock.gif)
78
![](/Images/OutliningIndicators/InBlock.gif)
79
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
82
![](/Images/OutliningIndicators/InBlock.gif)
83
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
86
![](/Images/OutliningIndicators/InBlock.gif)
87
![](/Images/OutliningIndicators/InBlock.gif)
88
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
89
![](/Images/OutliningIndicators/InBlock.gif)
90
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
91
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
92
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
93
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
94
![](/Images/OutliningIndicators/None.gif)
95
![](/Images/OutliningIndicators/None.gif)
96
![](/Images/OutliningIndicators/None.gif)
97
![](/Images/OutliningIndicators/None.gif)
98
![](/Images/OutliningIndicators/None.gif)
Handler.ashx页:
1
<%@ WebHandler Language="C#" Class="Handler" %>
2![](/Images/OutliningIndicators/None.gif)
3
using System;
4
using System.Web;
5![](/Images/OutliningIndicators/None.gif)
6
public class Handler : IHttpHandler {
7
8
public void ProcessRequest (HttpContext context) {
9
context.Response.ContentType = "text/plain";
10
string action = context.Request.Headers["action"].ToString();
11![](/Images/OutliningIndicators/InBlock.gif)
12
switch (action)
13
{
14
case "error":
15
throw new Exception();
16
break;
17
case "normal":
18
//for (int i = 0; i < context.Request.ServerVariables.Count; i++)
19
//{
20
// context.Response.Write(context.Request.ServerVariables.Keys[i] + "=" + context.Request.ServerVariables[i].ToString() + "\n");
21
//}
22
context.Response.Write("发送请求的网页URL:" + context.Request.ServerVariables["HTTP_REFERER"]);
23
context.Response.Write("\n发送过来的数据是:" + context.Request.Form["data"].ToString());
24
break;
25
case "timeout":
26
System.Threading.Thread.Sleep(5000);
27
break;
28
default:
29
context.Response.Write("非法的请求!");
30
break;
31
}
32
}
33
34
public bool IsReusable {
35
get {
36
return false;
37
}
38
}
39![](/Images/OutliningIndicators/InBlock.gif)
40
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
32
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
35
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
38
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
点个广告: