如何获取HttpWebRequest中的Header信息?

mendel 2008-02-12 11:15:19
如何获取HttpWebRequest中的Header信息?
...全文
884 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyi8808 2008-02-12
  • 打赏
  • 举报
回复
这个能得到更多信息:

<%@ 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>
wuyi8808 2008-02-12
  • 打赏
  • 举报
回复
<%
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>");
}
}
%>

110,618

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧