0
我想發佈的multipart/form-data的使用HttpClient的多文件與HttpClient的發送的multipart/form-data的
形式需要特定數量的圖像。
代碼:
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;
}
}
的問題是,只有最後一個圖像傳送!
爲什麼會發生這種情況?我錯過了什麼?以及如何解決這個問題?
在此先感謝..