HttpClient.PostAsync without await in VS 2010

This is a follow-up to this question:

How to upload file to server with HTTP POST multipart/form-data

It seems to be a good solution that uploads multipart form data. The library is available in VS 2010 through NuGet.

However, the code below uses await keyword, which is unavailable in VS 2010.

What would be a correct equivalent of that code without using 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; 
2

1 Answer

Do the same thing you did for the response content

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like