如何在web客户端类中获得包括post数据在内的所有标头
本文关键字:数据 post 客户端 web 包括 | 更新日期: 2023-09-27 18:04:44
我正在寻找一个代码示例如何在我的web应用程序中获得所有收到的标头,包括post数据。
如:
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*
有可能吗?
请求。标头将不包括发布的数据。发布的数据可以通过请求访问。
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...
}
您可能需要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服务器变量文档。