仅在WP8.1上:不能从HTTP流读取超过65536个字节 [英] On WP8.1 ONLY: cannot read more than 65536 bytes off an HTTP Stream

查看:102
本文介绍了仅在WP8.1上:不能从HTTP流读取超过65536个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望有人可以在我长时间困扰的问题上提供任何帮助.

Hope someone could please provide any help on an issue I'm struggling for quite a lot of time.

目标:我需要从指定的URI中读取http流,然后启动&不断阅读以下代码(我将其精简到最低限度,以便真正专注于裸露的通信问题):

Goal: I need to read an http stream from a specified URI, that I startup & endlessly read with the following code (which I stripped down to minimum so to really focus on the bare communication problem):

public void StartupStream(Uri uri)
{
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

    // Start the asynchronous request
    request.BeginGetResponse(OnGetResponse, request);
}
private void OnGetResponse(IAsyncResult asyncResult)
{
    // get the response
    HttpWebRequest req = (HttpWebRequest)asyncResult.AsyncState;
    try
    {
        using (HttpWebResponse resp = (HttpWebResponse)req.EndGetResponse(asyncResult))
        {
            using (Stream s = resp.GetResponseStream())
            {
                // dummy-read the stream forever
                int readBytes = 0;
                byte[] buffer = new byte[4096];
                while (true)
                {
                    readBytes += s.Read(buffer, 0, buffer.Length);
                }
            }
        }
    }
    catch (Exception ex)
    {
        throw;
    }
    finally
    {
        req.Abort();
    }
}

问题:碰巧,上面相同的代码可以完美地在演示桌面WPF应用程序上运行,读取千兆字节"的数据而没有任何问题,而在Windows Phone 8.1 Store应用程序上我只能读取最多65536个字节,然后对s.Read(buffer,0,buffer.Length)的后续调用(在无限while循环中)将永远挂起,而没有任何异常!

Issue: it happens that the above same exact code perfectly runs on a demo desktop WPF app, reading "gigabytes" of data without any issue, whereas on a Windows Phone 8.1 Store App I can only read up to 65536 bytes, and then the subsequent call to s.Read(buffer, 0, buffer.Length) (in the infinite while loop) just hangs forever, without any exception!

我已经尝试过的东西,没有任何结果:

  • 更改缓冲区大小的几个值(即256、512、1024…和 等等)
  • 在设备和仿真器上运行WP 8.1应用程序
  • 使用WireShark嗅探流量,我可以看到在WPF和WP 8.1方案上启动请求都完全相同,并且都是HTTP 1.1,并且在所有情况下,服务器(D-link DCS-920网络摄像头)都会继续将HTTP 1.1响应(mjpeg数据)完美地抽取"到流中.
  • Changing several values for the buffer size (i.e. 256, 512, 1024… and so on)
  • Running the WP 8.1 app on both device and emulator
  • Sniffing traffic with WireShark, I can see the startup request is exactly the same on both WPF and WP 8.1 scenarios, and both are HTTP 1.1, and in all cases, the server (a D-link DCS-920 webcam) continues to flawlessly "pump" HTTP 1.1 responses (mjpeg data) into the stream

有人知道在WP 8.1上使用这种简单的HTTP Stream会发生什么情况吗?读取中如何有65536字节的限制?

Does anybody have an idea of what could be going on with this bare, simple HTTP Stream usage on WP 8.1? How could there be a 65536-byte limitation on reads?

感谢您的帮助!

推荐答案

这是我从网络上下载图像的方式.该示例中的文件大小为1131683

This is how I am downloading an images from the web. The file size in the example is 1131683

     string URL = "http://img.uuhy.com/uploads/2010/05/4423_Free-high-resolution-desktop-wallpaper-8.jpg"; 
        var httpClient = new HttpClient();
        var httpResponse = await httpClient.GetAsync(URL);

       var ImageArray = await httpResponse.Content.ReadAsByteArrayAsync();

这篇关于仅在WP8.1上:不能从HTTP流读取超过65536个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆