C# 在VS 2010中无等待的HttpClient.PostAsync
这是对这一问题的后续行动: 上传多部分表单数据似乎是一个很好的解决方案。该库在VS2010中通过NuGet提供 但是,下面的代码使用了C# 在VS 2010中无等待的HttpClient.PostAsync,c#,asynchronous,async-await,httpclient,C#,Asynchronous,Async Await,Httpclient,这是对这一问题的后续行动: 上传多部分表单数据似乎是一个很好的解决方案。该库在VS2010中通过NuGet提供 但是,下面的代码使用了wait关键字,这在VS 2010中不可用 如果不使用wait,该代码的正确等价物是什么 HttpClient httpClient = new HttpClient(); MultipartFormDataContent form = new MultipartFormDataContent(); form.Add(new StringContent(use
wait
关键字,这在VS 2010中不可用
如果不使用wait
,该代码的正确等价物是什么
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;
对响应内容执行相同的操作
HttpResponseMessage response = httpClient.PostAsync("PostUrl", form).Result;
与您对reaponse内容所做的操作相同
HttpResponseMessage response=httpClient.PostAsync(“postrl”,form)。Result
httpClient是.NET 4.5的新版本,Visual studio 2010不使用.NET 4.5。与您对reaponse内容所做的操作相同HttpResponseMessage response=httpClient.PostAsync(“postrl”,form).Result
HttpClient是.NET 4.5的新版本,Visual studio 2010不使用.NET 4.5.Hi Nkosi,我也在使用相同的代码,但没有wait关键字。它为超过40万用户提供服务。但有时会出现这种例外。这是什么原因?你知道吗System.Threading.Tasks.TaskCanceledException:一个任务被取消。嗨,Nkosi,我也在使用相同的代码,没有wait关键字。它为超过40万用户提供服务。但有时会出现这种例外。这是什么原因?你知道吗System.Threading.Tasks.TaskCanceledException:任务已取消。