繁体   English   中英

在VS 2010中没有等待的HttpClient.PostAsync

[英]HttpClient.PostAsync without await in VS 2010

这是这个问题的后续行动:

如何使用HTTP POST multipart / form-data将文件上传到服务器

上传多部分表单数据似乎是一个很好的解决方案。 该库可通过NuGet在VS 2010中使用。

但是,下面的代码使用await关键字,该关键字在VS 2010中不可用。

没有使用await ,该代码的正确等价是什么?

HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();

form.Add(new StringContent(username), "username");
form.Add(new StringContent(useremail), "email");
form.Add(new StringContent(password), "password");
form.Add(new StringContent(usertype), "user_type");
form.Add(new StringContent(subjects), "subjects");
form.Add(new ByteArrayContent(imagebytearraystring, 0, imagebytearraystring.Count()), "profile_pic", "hello1.jpg");
HttpResponseMessage response = await httpClient.PostAsync("PostUrl", form);

response.EnsureSuccessStatusCode();
httpClient.Dispose();
string sd = response.Content.ReadAsStringAsync().Result;

为响应内容做同样的事情

HttpResponseMessage response = httpClient.PostAsync("PostUrl", form).Result;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM