HttpContent.ReadAsStringAsync causes request to hang (or other strange behaviours)

前端 未结 2 1905
青春惊慌失措
青春惊慌失措 2021-01-11 18:29

We are building a highly concurrent web application, and recently we have started using asynchronous programming extensively (using TPL and async/await

2条回答
  •  爱一瞬间的悲伤
    2021-01-11 19:04

    I had this problem. Although, I haven't fully tested yet, using CopyToAsync instead of ReadAsStringAsync seems to fix the problem:

    var ms = new MemoryStream();
    await response.Content.CopyToAsync(ms);
    ms.Seek(0, SeekOrigin.Begin);
    
    var sr = new StreamReader(ms);
    responseContent = sr.ReadToEnd();
    

提交回复
热议问题