且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

做多部分时如何从httpclient C#获取响应主体

更新时间:2023-01-03 17:23:45

要回显Jon(一个人并不完全不同意Jon),请不要将async/await世界与pre-async/await(ContinueWith)混合使用世界.

To echo Jon (one does not simply disagree with Jon), do not mix the async/await world with the pre-async/await (ContinueWith) world.

要以字符串形式获取响应正文,您需要第二次等待:

To get the response body as a string you need a 2nd await:

var response = await client.PostAsync(fileUploadUrl, content);
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();