以下代码从MJPEG视频流中读取字节。 它在Windows 8.1 Store应用程序上运行良好,但在Windows Phone 8.1应用程序中相同的代码失败。
读取65536字节方法"读取"不从流中读取更多字节。
On WP8.1 ONLY: cannot read more than 65536 bytes off an HTTP Stream
中的同样问题有人告诉属性DefaultMaximumErrorResponseLength,但此属性仅在WPF中(不在Windows商店.net中)
WP8.1上的WebClient类也存在同样的问题。
(在On WP8.1 ONLY: cannot read more than 65536 bytes off an HTTP Stream中说WebClient没有这个问题,但它不是真的)
示例代码:
var request = (HttpWebRequest)WebRequest.CreateHttp("http://webcam.st-malo.com/axis-cgi/mjpg/video.cgi?resolution=352x288");
request.AllowReadStreamBuffering = false;
request.BeginGetResponse(OnGetResponse, request);
private void OnGetResponse(IAsyncResult asyncResult)
{
HttpWebRequest req = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse resp = (HttpWebResponse)req.EndGetResponse(asyncResult);
Stream s = resp.GetResponseStream();
byte[] buff = new byte[ChunkSize];
int readed;
do
{
readed = s.Read(buff, 0, ChunkSize);
}
while (readed > 0);
}