HttpClient 上传图片

            Image image = Image.FromFile(@"F:\image2\DSC02028.JPG");
var data = ImageToByteArray(image); var requestContent = new MultipartFormDataContent();
// here you can specify boundary if you need---^
var imageContent = new ByteArrayContent(data);
imageContent.Headers.ContentType =
MediaTypeHeaderValue.Parse("image/jpeg"); requestContent.Add(imageContent, "image", "image.jpg");
using (var client = new HttpClient())
{ client.BaseAddress = new Uri("http://127.0.0.1:5000"); var result = client.PostAsync("/api/values", requestContent).Result; //result.Content.ReadAsStringAsync().Result; }
上一篇:js调试系列: 源码定位与调试[基础篇]


下一篇:jQuery Ajax 实例 ($.ajax、$.post、$.get)