Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在VS 2010中无等待的HttpClient.PostAsync_C#_Asynchronous_Async Await_Httpclient - Fatal编程技术网

C# 在VS 2010中无等待的HttpClient.PostAsync

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

这是对这一问题的后续行动:

上传多部分表单数据似乎是一个很好的解决方案。该库在VS2010中通过NuGet提供

但是,下面的代码使用了
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:任务已取消。