还是关于在VS2005中HttpWorkerRequest.GetPreloadedEntityBody()取不到数据的问题
做一个HttpModule ,用GetPreloadedEntityBody()取数据总是报引用空的异常.(同样代码在2003中可以).在BAIDU和GOOGLE上也搜到类似问题,但是没有看到答案...求教了!!
------解决方案--------------------//以前的帖子回复
IServiceProvider provider = (IServiceProvider) HttpContext.Current;
HttpWorkerRequest wr = (HttpWorkerRequest) provider.GetService(typeof(HttpWorkerRequest));
string addr = wr.GetLocalAddress();
Response.Write(String.Format( "NiC Address:{0} <BR> ", addr));
byte[] bs = wr.GetPreloadedEntityBody();
String s = " ";
if (bs != null && bs.Length > 0)
s= System.Text.Encoding.Default.GetString(bs);
Response.Write(s + " <BR> ");
if (!wr.IsEntireEntityBodyIsPreloaded())
{
Response.Write( "normally shouldn 't be here ");
int n = 1024;
byte[] bs2 = new byte[n];
while (wr.ReadEntityBody(bs2,n) > 0)
{
s = System.Text.Encoding.Default.GetString(bs2);
Response.Write(s + " <BR> ");
}
}
note, as IIS receives data on its TCP/IP connection from the browser, it sends a copy to the ASP.NET worker process through a named pipe. You use ReadEntityBody to read the data from this pipe. But you might not need to use ReadEntityBody if the data is not huge