Transfer Encoding: Tagged in Windows Phone

I have a server response with Transfer-Encoding: chunked

HTTP/1.1 200 OK Server: nginx/1.2.1 Date: Mon, 18 Feb 2013 08:22:49 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding c7 {<some json data>} 0 

See the c7 chunk size before json data.

How can I read a raw response stream without chunks in Windows Phone using HttpWebResponse ?


Hint: to make a conclusion to disable the output of the string, I just need to specify the version of the HTTP / 1.0 protocol. But I don’t know how to do this, because in the HttpWebRequest class HttpWebRequest no ProtocolVersion class in Windows Phone or Silverlight

+4
source share
2 answers

HttpClient is able to automatically analyze the output stream http://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx

HttpClient is a cool thing with PostAsync and GetAsinc, as well as many other goodies. I never use HttpWebRequest again.

HttpClient easily available in .NET Framework 4.5, Windows 8 or Windows Phone 8.1

Use the NuGet package http://www.nuget.org/packages/Microsoft.Net.Http if you need HttpClient in the -NET Framework 4 - Windows Phone Silverlight 7.5 - Silverlight 4 - Portable Class Libraries

+1
source

You can read the fragmented answer as follows:

 public static byte[] ReadChunkedResponse(this WebResponse response) { byte[] buffer; using (var stream = response.GetResponseStream()) { using (var streamReader = new StreamReader(stream, Encoding.UTF8)) { var content = new StringBuilder(); while (!streamReader.EndOfStream) { content.Append((char)streamReader.Read()); } buffer = Encoding.UTF8.GetBytes(content.ToString()); } } return buffer; } 
0
source

All Articles