如何获取HttpWebRequest中的Header信息?

解决方案 »

  1.   

    <%
    int loop1, loop2;
    NameValueCollection coll;
     
    // Load Header collection into NameValueCollection object.
    coll=Request.Headers;// Put the names of all keys into a string array.
    String[] arr1 = coll.AllKeys; 
    for (loop1 = 0; loop1<arr1.Length; loop1++) 
    {
       Response.Write("Key: " + arr1[loop1] + "<br>");
       // Get all values under this key.
       String[] arr2=coll.GetValues(arr1[loop1]);
       for (loop2 = 0; loop2<arr2.Length; loop2++) 
       {
          Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
       }
    }
    %>
      

  2.   

    这个能得到更多信息:<%@ Page Language="C#"%>
    <script runat="server">    private void Page_Load(object sender, EventArgs e)
        {
            // Create a string to contain the paramaters'
            // information.
            string paramInfo = "";        // Obtain a reference to the Request.Params
            // collection.
            NameValueCollection pColl = Request.Params;        // Iterate through the collection and add
            // each key to the string variable.
            for(int i = 0; i <= pColl.Count - 1; i++)
            {
                paramInfo += "Key: " + pColl.GetKey(i) + "<br>";            // Create a string array that contains
                // the values associated with each key.
                string[] pValues = pColl.GetValues(i);            // Iterate through the array and add
                // each value to the string variable.
                for(int j = 0; j <= pValues.Length - 1; j++)
                {
                    paramInfo += "Value:" + pValues[j] + "<br><br>";            }
            }        // Set a Label's Text property to the values
            // contained in the string variable.
            lblValues.Text = paramInfo;
        }</script>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
            <asp:Label id="lblValues" runat="server" />
        </form>
    </body>
    </html>