2008-09-16 94 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服務器來託管必須接受大 二進制流流 數據服務。