I'm trying to post a multipart/form-data Using HttpClient
the form requires a certain number of images.
Code :
var client = new System.Net.Http.HttpClient();
var content = new MultipartFormDataContent();
var postData = new List<KeyValuePair(string,string)> ();
postData.Add(new KeyValuePair < string, string > ("function", "picture2"));
postData.Add(new KeyValuePair < string, string > ("username ", UserID));
postData.Add(new KeyValuePair < string, string > ("password ", Password));
foreach(var keyValuePair in postData) {
content.Add(new StringContent(keyValuePair.Value),
String.Format("\"{0}\"", keyValuePair.Key));
}
int x = 1;
foreach(Bitmap item in newpics) {
using(MemoryStream ms = new MemoryStream()) {
item.Save(ms, ImageFormat.Bmp);
byte[] bits = ms.ToArray();
content.Add(new ByteArrayContent(bits), '"' + "pict" + x + '"');
x += 1;
}
}
The problem is that only the last image is delivered !!
why does this happen?? what did i miss? and how to fix this problem?
Thanks in advance..
This is an example of how to post string and file stream with HTTPClient using MultipartFormDataContent. The Content-Disposition and Content-Type need to be specified for each HTTPContent:
Here's my example. Hope it helps:
var path = @"C:\B2BAssetRoot\files\596086\596086.1.mp4";