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

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

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest