62,073
社区成员
发帖
与我相关
我的任务
分享
static void NetHttpTest()
{
using (var client = new HttpClient())
{
using (var content = new MultipartFormDataContent())
{
client.BaseAddress = new Uri("http://localhost:16724/");
var fileContent = new ByteArrayContent(File.ReadAllBytes(@"c:\work\thumb.jpg"));
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "thumb.jpg"
};
content.Add(fileContent);
fileContent = new ByteArrayContent(File.ReadAllBytes(@"c:\work\image.jpg"));
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "image.jpg"
};
content.Add(fileContent);
var dic = new Dictionary<string, string>();
dic.Add("key", "ABCDEFGH12345678");
dic.Add("id", "1");
//…… and so on
var dataContent = new FormUrlEncodedContent(dic);
content.Add(dataContent);
var result = client.PostAsync("/api/set_room", content).Result;
Console.WriteLine(result.StatusCode);
}
}
}
参考下这种通过HttpClient上传的方式是否可行