0

我正在寻找一个代码示例,如何在我的 Web 应用程序中获取所有接收到的标头,包括发布数据。

比如:

String headers = client.Headers.ToString(); 
Response.Write(headers); 

输出:

       POST http://localhost:52133/test/Default.aspx HTTP/1.1
        Host: localhost:52133
        User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1
        Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
        Connection: keep-alive
        foo: baa
        Pragma: no-cache


      *the post data*

可能吗?

4

2 回答 2

1

Request.Headers will not include the posted data. The posted data can be accessed via Request.Form object like the following:

 for(int i = 0; i < Request.Form.Count; i++)
 {
     string key = Request.Form.GetKey(i);
     string value = Request.Form[i];
     // now do something with the key-value pair...
 }
于 2011-08-08T18:00:53.957 回答
0

您可能想要该Request.ServerVariables物业。你可以像这样循环遍历它:

Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection

' Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables 
' Get names of all keys into a string array.
arr1 = coll.AllKeys 
For loop1 = 0 To arr1.GetUpperBound(0)
   Response.Write("Key: " & arr1(loop1) & "<br>")
   arr2 = coll.GetValues(loop1) ' Get all values under this key.
   For loop2 = 0 To arr2.GetUpperBound(0)
      Response.Write("Value " & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)) & "<br>")
   Next loop2
Next loop1

以“HEADER_”开头的是原始 HTTP 标头。有关详细信息,请参阅 MSDN 的IIS 服务器变量文档

于 2011-08-05T23:26:02.377 回答