Skip to content

Instantly share code, notes, and snippets.

@jeremysimmons
Created August 23, 2022 00:57
Show Gist options
  • Select an option

  • Save jeremysimmons/607f9b89fa2e4611872aa4f33cdefd89 to your computer and use it in GitHub Desktop.

Select an option

Save jeremysimmons/607f9b89fa2e4611872aa4f33cdefd89 to your computer and use it in GitHub Desktop.
HttpClient MultipartFormDataContent
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 ByteArrayContent(file_bytes, 0, file_bytes.Length), "profile_pic", "hello1.jpg");
HttpResponseMessage response = await httpClient.PostAsync("PostUrl", form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
string sd = response.Content.ReadAsStringAsync().Result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment