Canonical
How can I make an HTTP request and send some data using thePOST
method?
Yet another way of doing it:
using (HttpClient httpClient = new HttpClient())
using (MultipartFormDataContent form = new MultipartFormDataContent())
{
form.Add(new StringContent(param1), "param1");
form.Add(new StringContent(param2), "param2");
using (HttpResponseMessage response = await httpClient.PostAsync(url, form))
{
response.EnsureSuccessStatusCode();
string res = await response.Content.ReadAsStringAsync();
return res;
}
}
This way you can easily post a stream.