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。 –