我正在尝试通过 EventSource / Server-Sent Events 协议在 Windows Phone 上使用 Firebase API。
当我不设置Accept: text/event-stream
. 通过这种方式,我得到了整个请求的 json。但是当Accept设置为text/event-stream时,任务不会继续。
request.AllowReadStreamBuffering
设置为它false
不会改变
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.AllowAutoRedirect = true;
request.Accept = "text/event-stream";
//request.AllowReadStreamBuffering = false;
Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse,
request.EndGetResponse,
null)
.ContinueWith(async t =>
{
using (Stream s = t.Result.GetResponseStream())
{
byte[] buffer = new byte[1024 * 8];
int bytesRead = await s.ReadAsync(buffer, 0, buffer.Length);
string content = Encoding.UTF8.GetString(buffer, 0, bytesRead);
System.Diagnostics.Debug.WriteLine(content);
}
});
谢谢!