一般处理程序ashx能否获得完整的原始的请求头信息?是原始的,尚未解析的请求头字符串信息!!!
using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.RegularExpressions;namespace idCheck.net.genealogy
{
/// <summary>
/// getMessages 的摘要说明
/// </summary>
public class getMessages : IHttpHandler
{ personMessage pm = new personMessage();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string requestHeader = // 这里该如何写???用于获取原始的不是解析后的请求头字符串信息!!!
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.RegularExpressions;namespace idCheck.net.genealogy
{
/// <summary>
/// getMessages 的摘要说明
/// </summary>
public class getMessages : IHttpHandler
{ personMessage pm = new personMessage();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string requestHeader = // 这里该如何写???用于获取原始的不是解析后的请求头字符串信息!!!
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
sb.Append(Program.httpServer.Info);
if (context.Request.Headers.Count > 0)
{
sb.Append("<hr />你的浏览器信息:<br />");
for (var i = 0; i < context.Request.Headers.Count; i++)
{
var k = context.Request.Headers.GetKey(i);
var x = context.Request.Headers.GetValues(i);
sb.Append(HttpUtility.HtmlEncode(string.Format("{0}={1}", k, string.Join(",", x))) + "<br />");
}
}
sb.Append("</html>");
谢谢 sp234:你的程序中:Program.httpServer.Info 是什么?需要引用什么?百度不到相关的信息啊其实在 ashx 中,用 context.Request.SaveAs("d:\\111.bin", true); 就可以把请求的所有数据保存到文件中,自然可以获取完整的请求头,只是它必须保存到磁盘文件中,效率比较低下,现在想寻求一种高效的方法,获取的信息样式比如:POST /net/genealogy/getMessages.ashx HTTP/1.1
Connection: keep-alive
Content-Length: 0
Content-Type: application/xml
Accept: */*
Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Cookie: genealogyId=8
Host: localhost:49169
Referer: http://localhost:49169/net/genealogy/do.html
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11
Origin: http://localhost:49169
X-Requested-With: XMLHttpRequest
你的循环虽然可以获取一些信息,但是解析以后的,和上面的是有差别的啊~~~