Windowsphone で httpClient からの応答のストリーミング結果を取得する方法はありますか? WP7.1+ の PCL ターゲットに次のコードがあります (コードを電話プロジェクト自体に移動した場合と同じ問題)。ストアアプリ。
HttpResponseMessage が利用可能になると、既に Content-Length が指定されています -- ゆっくりといっぱいになるこのデータ ストリームに対しては 0 です。
Connection Keep-Alive ヘッダーを指定しようとしましたが、電話でそのヘッダーを指定すると、「ヘッダーの Connection に空の値があります」という ArgumentException が発生します。ストアアプリはそれで問題ありません
resp = m_httpClientStream.SendAsync(request,
HttpCompletionOption.ResponseHeadersRead, m_ctsStream.Token);
resp.ContinueWith(
(responseTask) =>
{
HttpResponseMessage respMsg;
try
{
respMsg = responseTask.Result;
}
catch (Exception e)
{
return;
}
Task<Stream> respStream = respMsg.Content.ReadAsStreamAsync();
respStream.ContinueWith(
async (respStreamTask) =>
{
Stream streamResp = respStreamTask.Result;
int read = 0;
do
{
byte[] responseBuffer = new byte[500];
read = await streamResp.ReadAsync(responseBuffer, 0, responseBuffer.Length);
string result = Encoding.UTF8.GetString(responseBuffer, 0, read);
//callback
} while (read != 0);
});
});