1
等待这是一个后续行动这样一个问题:HttpClient.PostAsync没有VS 2010
How to upload file to server with HTTP POST multipart/form-data
这似乎是上传多形式的数据很好的解决方案。该图书馆通过NuGet在VS 2010中提供。
但是,下面的代码使用await
关键字,这是在2010年VS
不可用什么将是该代码的正确相当于不使用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;
你做的reaponse内容'HttpResponseMessage响应同样的事情= httpClient.PostAsync( “PostUrl” 形式).Result' – Nkosi
的HttpClient是.NET 4.5的新增功能,Visual Studio 2010不使用.NET 4.5。 –