在ASP.NET中關於分塊傳輸編碼的HTTP請求的閱讀體 (Reading Body on chunked transfer encoded http requests in ASP.NET)


問題描述

在 ASP.NET 中讀取分塊傳輸編碼的 http 請求的正文 (Reading Body on chunked transfer encoded http requests in ASP.NET)

分塊主機:somesite.com:15148</p>

Body rabbits rabbits rabbits rabbits。謝謝你的到來,它非常有用!

我上面的正文閱讀器將返回一個零長度字節數組......蹩腳......

有誰知道如何啟用分塊編碼在 IIS 和 ASP.NET 開發服務器 (cassini) 上?

我發現 此腳本 用於 IIS,但它不起作用。


參考解法

方法 1:

Seems to be official: Cassini does not support Transfer‑Encoding: chunked requests.

By default, the client sends large binary streams by using a chunked HTTP Transfer‑Encoding. Because the ASP.NET Development Server does not support this kind of encoding, you cannot use this Web server to host a streaming data service that must accept large binary streams.

方法 2:

That url does not work any more, so it's hard to test this directly. I wondered if this would work, and google turned up someone who has experience with it at bytes.com. If you put your website up again, I can see if this really works there.

Joerg Jooss wrote: (slightly modified for brevity )

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());
}

(by CVertexAnton TykhyyAndrew)

參考文件

  1. Reading Body on chunked transfer encoded http requests in ASP.NET (CC BY‑SA 2.5/3.0/4.0)

#ASP.NET #chunked-encoding #asp.net-mvc






相關問題

System.Reflection.Assembly.LoadFile 鎖定文件 (System.Reflection.Assembly.LoadFile Locks File)

如何在沒有全局變量的情況下一直保留我的變量? (How can I keep my variable all the time without global variables?)

C# / ASP.NET - Web 應用程序鎖定 (C# / ASP.NET - Web Application locking)

關閉模態對話框窗口後 ASP.NET 刷新父頁面 (ASP.NET Refresh Parent Page after Closing Modal Dialog Window)

無法將 NULL 值傳遞給數據庫 (Unable to pass NULL value to database)

wcf:將用戶名添加到消息頭是否安全? (wcf: adding username to the message header is this secure?)

使用 ASP.Net 教初學者 Web 開發的小項目想法 (Small projects ideas to teach beginners web development using ASP.Net)

SQL Server - 分組、擁有和計數 (SQL Server - Group by, having and count in a mix)

企業庫異常處理應用程序塊和日誌記錄應用程序塊在 ASP.NET 中的正確使用 (Enterprise Library Exception Handling Application Block and Logging Application Block proper use in ASP.NET)

來自proc的asp.net多個結果集:是否有必要將結果映射到類?如果是這樣,怎麼做? (asp.net multiple result set from proc: is it necessary to map results to class? If so, how?)

如何在測試工具中實例化 asp.net 代碼隱藏類? (How can I instantiate an asp.net codebehind class in a test harness?)

Web 窗體用戶控制事件,需要在頁面加載後添加 (Web Form User Control Event, needs to be added after page loads)







留言討論