Body reading on chunked transfer of encoded HTTP requests in ASP.NET

The J2ME client sends POST HTTP requests with encoding of packet transfers.

When ASP.NET (both in IIS6 and WebDev.exe.server) tries to read the request, it sets the Content-Length to 0. I think this is normal, because the length of the content is unknown when the request is loaded.

However, when I read Request.InputStream to the end, it returns 0.

Here is the code that I use to read the input stream.

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

I can simulate client behavior using Fiddler, for example

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

Headers: User Agent: Fiddler Transmission Encoding: Chunked Host: somesite.com:15148

The body of rabbits is rabbits rabbits rabbits rabbits. Thank you for being very helpful!

My body reader on top will return an array of bytes with zero length ... lame ...

Does anyone know how to enable chunked encoding on IIS and ASP.NET Development Server (cassini)?

I found this script for IIS, but it does not work.

+4
source share
2 answers

Seems official: Cassini does not support Transfer-Encoding: chunked requests.

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

+2
source

This url no longer works, so it’s hard to check it directly. I was wondering if this would work, and google attracted someone who has experience with him at bytes.com . If you host your site again, I can see if this really works.

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

Source: https://habr.com/ru/post/1276725/


All Articles