Coding Bots

Making MultipartForm HttpClient request from Windows Phone 8.1

Hey Everyone, today  m going to tell you how to make a MultipartForm HttpClient  request from C# or in simple words you can say that “to send a multiple Post actions to a web in one httpclient request ”


so lets get started.

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("");

MultipartFormDataContent form = new MultipartFormDataContent();

// for string type
HttpContent content  = new StringContent("your string type data you want to post");
form.Add(content, "name"); // name with which you will get its access on web (e-g: PHP)
// for image type
var stream = await file.OpenStreamForReadAsync(); // "file" is a StorageFile object of image
content = new StreamContent(stream);
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
Name = "image", // name with which you will get its access on web (e-g: PHP)
FileName = file.Name

var response = await client.PostAsync("index.php", form);
// response will be shown using the following code
mytextblock.Text = response.Content.ReadAsStringAsync();

Thank you 🙂


Exit mobile version