- 応答全体がストリーミングされる前に、応答ヘッダーにアクセスするにはどうすればよいですか?
- ストリームが到着したときにどのように読むのですか?
- HttpClient は、http 応答の受信をきめ細かく制御するための最良の選択ですか?
ここに私の質問を説明するかもしれないスニップがあります:
using (var response = await _httpClient.SendAsync(request,
HttpCompletionOption.ResponseHeadersRead))
{
var streamTask = response.Content.ReadAsStreamAsync();
//how do I check if headers portion has completed?
//Does HttpCompletionOption.ResponseHeadersRead guarantee that?
//pseudocode
while (!(all headers have been received))
//maybe await a Delay here to let Headers get fully populated
access_headers_without_causing_entire_response_to_be_received
//how do I access the response, without causing an await until contents downloaded?
//pseudocode
while (stremTask.Resul.?) //i.e. while something is still streaming
//? what goes here? a chunk-read into a buffer? or line-by-line since it's http?
...
私にとって別の灰色の領域を明確にするために編集します。
私が発見した参照には、コンテンツが到着するのを待つ原因となる何らかのブロッキングステートメントがあります。私が読んだ参照は通常、streamTask.Result または Content のメソッドまたはプロパティにアクセスしますが、streamTask が進行しているときにどのような参照が問題ないか、タスクが完了するまで待機を引き起こす可能性がある参照を除外するのに十分な情報がありません。完了します。