HTTP 协议演示——概述(2-5)

如果用 .NET 创建一个空的页面,.aspx 文件内容如下。

代码段一
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        </div>
    </form>
</body>
</html>

以上页面没有任何控件。然后用 IE 查看它的源文件。如下所示。

代码段二
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
        <div>
            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" 
value="/wEPDwUJNzgzNDMwNTMzZGT8XigVHlmkk+BXiblfwYUp8bVAIA==" />
        </div>
        <div>
        </div>
    </form>
</body>
</html>

即便没有任何控件,但在它的源代码文件中还是有个隐藏域。如果向这个页面添加一个 HTML 文本框,.aspx 文件内容如下所示。

代码段三
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input id="Text1" type="text" /></div>
    </form>
</body>
</html>

再查看它的源文件,如下所示。

代码段四
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
        <div>
            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" 
value="/wEPDwUJNzgzNDMwNTMzZGT8XigVHlmkk+BXiblfwYUp8bVAIA==" />
        </div>
        <div>
            <input id="Text1" type="text" />
        </div>
    </form>
</body>
</html>

此时,除了隐藏域,就是真正的 HTML 文本框。如果向这个页面添加一个 ASP.NET 控件,.aspx 文件内容如下所示。

代码段五
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
    </form>
</body>
</html>

查看它的源文件,如下所示。

代码段六
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
    <div>
        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" 
value="/wEPDwUJMjgzMDgzOTgzZGRQ4cwjxigvH0cn0g6XWSHkZbN2Lg==" />
    </div>
    <div>
        <input name="TextBox1" type="text" id="TextBox1" /></div>
    <div>
        <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" 
value="/wEWAgKo3JKxDwLs0bLrBrEWYCZVJeodiUUqcdX2kqmQDHGa" /></div>
    </form>
</body>
</html>

此时的源文件,多了一个。两个隐藏域,分别是 "__VIEWSTATE""__EVENTVALIDATION",再就是 HTML 文本框。

另外,我们知道 ASP.NET 程序中,有几个一直存在的对象,Server 对象,Response 对象,Request 对象等等。如果我们调试一下 ASP.NET 程序,看看 Response 和 Request 对象都有些什么。

对于 Request 对象,你可能看到如下一堆信息。

代码段七
AcceptTypes: {Dimensions:[1]}
AnonymousID: null
ApplicationPath: "/"
AppRelativeCurrentExecutionFilePath: "~/Default.aspx"
Browser: {System.Web.Mobile.MobileCapabilities}
ClientCertificate: {System.Web.HttpClientCertificate}
ContentEncoding: {System.Text.UTF8Encoding}
ContentLength: 0
ContentType: ""
Cookies: {System.Web.HttpCookieCollection}
CurrentExecutionFilePath: "/Default.aspx"
FilePath: "/Default.aspx"
Files: {System.Web.HttpFileCollection}
Filter: {System.Web.HttpInputStreamFilterSource}
Form: {}
Headers: {Connection=Keep-Alive&;;Accept=*%2f*&Accept-Encoding=gzip%2c+deflate&Accept-Language=zh-cn&Host=localhost%3a1234&User-Agent=Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)&UA-CPU=x86}
HttpMethod: "GET"
InputStream: {System.Web.HttpInputStream}
IsAuthenticated: false
IsLocal: true
IsSecureConnection: false
LogonUserIdentity: {System.Security.Principal.WindowsIdentity}
Params: {ALL_HTTP=HTTP_CONNECTION%3aKeep-Alive%0d%0aHTTP_ACCEPT%3a*%2f*%0d%0aHTTP_ACCEPT_ENCODING%3agzip%2c+deflate%0d%0aHTTP_ACCEPT_LANGUAGE%3azh-cn%0d%0aHTTP_HOST%3alocalhost%3a1234%0d%0aHTTP_USER_AGENT%3aMozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)%0d%0aHTTP_UA_CPU%3ax86%0d%0a&;;ALL_RAW=Connection%3a+Keep-Alive%0d%0aAccept%3a+*%2f*%0d%0aAccept-Encoding%3a+gzip%2c+deflate%0d%0aAccept-Language%3a+zh-cn%0d%0aHost%3a+localhost%3a1234%0d%0aUser-Agent%3a+Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)%0d%0aUA-CPU%3a+x86%0d%0a&APPL_MD_PATH=%2fLM%2fW3SVC%2f1860662192%2fRoot&APPL_PHYSICAL_PATH=D%3a%5cMyTest%5cWebSite1%5c&AUTH_TYPE=&AUTH_USER=&AUTH_PASSWORD=&LOGON_USER=&REMOTE_USER=&CERT_COOKIE=&CERT_FLAGS=&CERT_ISSUER=&CERT_KEYSIZE=&CERT_SECRETKEYSIZE=&CERT_SERIALNUMBER=&CERT_SERVER_ISSUER=&CERT_SERVER_SUBJECT=&CERT_SUBJECT=&CONTENT_LENGTH=0&CONTENT_TYPE=&GATEWAY_INTERFACE=CGI%2f1.1&HTTPS=off&HTTPS_KEYSIZE=&H
_SECRETKEYSIZE=&;;HTTPS_SERVER_ISSUER=&HTTPS_SERVER_SUBJECT=&INSTANCE_ID=1860662192&INSTANCE_META_PATH=%2fLM%2fW3SVC%2f1860662192&LOCAL_ADDR=127.0.0.1&PATH_INFO=%2fDefault.aspx&PATH_TRANSLATED=D%3a%5cMyTest%5cWebSite1%5cDefault.aspx&QUERY_STRING=&REMOTE_ADDR=127.0.0.1&REMOTE_HOST=127.0.0.1&REMOTE_PORT=46201&REQUEST_METHOD=GET&SCRIPT_NAME=%2fDefault.aspx&SERVER_NAME=localhost&SERVER_PORT=1234&SERVER_PORT_SECURE=0&SERVER_PROTOCOL=HTTP%2f1.1&SERVER_SOFTWARE=Microsoft-IIS%2f6.0&URL=%2fDefault.aspx&HTTP_CONNECTION=Keep-Alive&HTTP_ACCEPT=*%2f*&HTTP_ACCEPT_ENCODING=gzip%2c+deflate&HTTP_ACCEPT_LANGUAGE=zh-cn&HTTP_HOST=localhost%3a1234&HTTP_USER_AGENT=Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)&HTTP_UA_CPU=x86}
Path: "/Default.aspx"
PathInfo: ""
PhysicalApplicationPath: "D://MyTest//WebSite1//"
PhysicalPath: "D://MyTest//WebSite1//Default.aspx"
QueryString: {}
RawUrl: "/Default.aspx"
RequestType: "GET"
ServerVariables: {ALL_HTTP=HTTP_CONNECTION%3aKeep-Alive%0d%0aHTTP_ACCEPT%3a*%2f*%0d%0aHTTP_ACCEPT_ENCODING%3agzip%2c+deflate%0d%0aHTTP_ACCEPT_LANGUAGE%3azh-cn%0d%0aHTTP_HOST%3alocalhost%3a1234%0d%0aHTTP_USER_AGENT%3aMozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)%0d%0aHTTP_UA_CPU%3ax86%0d%0a&;;ALL_RAW=Connection%3a+Keep-Alive%0d%0aAccept%3a+*%2f*%0d%0aAccept-Encoding%3a+gzip%2c+deflate%0d%0aAccept-Language%3a+zh-cn%0d%0aHost%3a+localhost%3a1234%0d%0aUser-Agent%3a+Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)%0d%0aUA-CPU%3a+x86%0d%0a&APPL_MD_PATH=%2fLM%2fW3SVC%2f1860662192%2fRoot&APPL_PHYSICAL_PATH=D%3a%5cMyTest%5cWebSite1%5c&AUTH_TYPE=&AUTH_USER=&AUTH_PASSWORD=&LOGON_USER=&REMOTE_USER=&CERT_COOKIE=&CERT_FLAGS=&CERT_ISSUER=&CERT_KEYSIZE=&CERT_SECRETKEYSIZE=&CERT_SERIALNUMBER=&CERT_SERVER_ISSUER=&CERT_SERVER_SUBJECT=&CERT_SUBJECT=&CONTENT_LENGTH=0&CONTENT_TYPE=&GATEWAY_INTERFACE=CGI%2f1.1&HTTPS=off&HTTPS_K
ZE=&;;HTTPS_SECRETKEYSIZE=&HTTPS_SERVER_ISSUER=&HTTPS_SERVER_SUBJECT=&INSTANCE_ID=1860662192&INSTANCE_META_PATH=%2fLM%2fW3SVC%2f1860662192&LOCAL_ADDR=127.0.0.1&PATH_INFO=%2fDefault.aspx&PATH_TRANSLATED=D%3a%5cMyTest%5cWebSite1%5cDefault.aspx&QUERY_STRING=&REMOTE_ADDR=127.0.0.1&REMOTE_HOST=127.0.0.1&REMOTE_PORT=46201&REQUEST_METHOD=GET&SCRIPT_NAME=%2fDefault.aspx&SERVER_NAME=localhost&SERVER_PORT=1234&SERVER_PORT_SECURE=0&SERVER_PROTOCOL=HTTP%2f1.1&SERVER_SOFTWARE=Microsoft-IIS%2f6.0&URL=%2fDefault.aspx&HTTP_CONNECTION=Keep-Alive&HTTP_ACCEPT=*%2f*&HTTP_ACCEPT_ENCODING=gzip%2c+deflate&HTTP_ACCEPT_LANGUAGE=zh-cn&HTTP_HOST=localhost%3a1234&HTTP_USER_AGENT=Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)&HTTP_UA_CPU=x86}
TotalBytes: 0
Url: {http://localhost:1234/Default.aspx}
UrlReferrer: null
UserAgent: "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
UserHostAddress: "127.0.0.1"
UserHostName: "127.0.0.1"
UserLanguages: {Dimensions:[1]}

对于 Response 对象,你可能会看到如下内容。

代码段八
Buffer: true
BufferOutput: true
Cache: {System.Web.HttpCachePolicy}
CacheControl: "private"
Charset: "utf-8"
ContentEncoding: {System.Text.UTF8Encoding}
ContentType: "text/html"
Cookies: {System.Web.HttpCookieCollection}
Expires: 0
ExpiresAbsolute: {0001-1-1 0:00:00}
Filter: {System.Web.HttpResponseStreamFilterSink}
HeaderEncoding: {System.Text.UTF8Encoding}
IsClientConnected: true
IsRequestBeingRedirected: false
Output: {System.Web.HttpWriter}
OutputStream: {System.Web.HttpResponseStream}
RedirectLocation: null
Status: "200 OK"
StatusCode: 200
StatusDescription: "OK"
SuppressContent: false
posted @ 2012-10-09 23:55  船长&CAP  阅读(527)  评论(0编辑  收藏  举报
免费流量统计软件