2008-09-16 89 views
4

J2ME客户端正在发送带有分块传输编码的HTTP POST请求。阅读ASP.NET中分块传输编码http请求的正文

当ASP.NET(在IIS6和WebDev.exe.server中)试图读取请求时,它将Content-Length设置为0.我猜这样可以,因为当请求被加载时Content-length是未知的。

然而,当我读了Request.InputStream到最后,则返回0。

下面是我使用读取输入流的代码。

using (var reader = new StreamReader(httpRequestBodyStream, BodyTextEncoding)) { 
    string readString = reader.ReadToEnd(); 
    Console.WriteLine("CharSize:" + readString.Length); 
    return BodyTextEncoding.GetBytes(readString); 
} 

我可以用Fiddler来模拟客户端的行为,例如,

URL http://localhost:15148/page.aspx

头: 的User-Agent:提琴手 传输编码:分块 主持人:somesite.com:15148

身体 兔子兔子兔子兔子。感谢您的光临,这非常有用!从上面

我的身体的读者会返回一个零长度的字节数组... ...跛脚

有谁知道如何在IIS和ASP.NET开发服务器(卡西尼)实现分块编码?我发现this script为IIS,但它不工作。

回答

1

该网址无法正常工作,因此很难直接进行测试。我想知道这是否会起作用,并且谷歌在bytes.com发现了一个有经验的人。如果你再次把你的网站,我可以看到这是否真的在那里工作。

约尔格Jooss写道:(稍微修改为简洁

string responseText = null; 
WebRequest rabbits= WebRequest.Create(uri); 
using (Stream resp = rabbits.GetResponse().GetResponseStream()) { 
    MemoryStream memoryStream = new MemoryStream(0x10000); 
    byte[] buffer = new byte[0x1000]; 
    int bytes; 
    while ((bytes = resp.Read(buffer, 0, buffer.Length)) > 0) { 
     memoryStream.Write(buffer, 0, bytes); 
    } 
    // use the encoding to match the data source. 
    Encoding enc = Encoding.UTF8; 
    reponseText = enc.GetString(memoryStream.ToArray()); 
} 
2

似乎是官方:Cassini does not support Transfer-Encoding: chunked requests.

默认情况下,客户端通过使用发送大 二进制流分块HTTP 传输编码。 因为ASP.NET 开发服务器不支持 这种编码的,你不能使用 该Web服务器来托管必须接受大 二进制流流 数据服务。