- 在整个响应流回之前,如何访问响应标头?
- 我如何在流到达时读取它?
- 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 正在进行,哪些将导致等待直到任务完成。