码迷,mamicode.com
首页 > Web开发 > 详细

上传文件

时间:2015-07-26 16:58:46      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

using (Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient())
{
Windows.Web.Http.HttpMultipartFormDataContent form = new Windows.Web.Http.HttpMultipartFormDataContent();

Windows.Web.Http.HttpStreamContent snContent = new Windows.Web.Http.HttpStreamContent(((Stream)new MemoryStream(Encoding.UTF8.GetBytes(sn))).AsInputStream());
snContent.Headers.ContentDisposition = new Windows.Web.Http.Headers.HttpContentDispositionHeaderValue("form-data");
form.Add(snContent, "sn");

Windows.Web.Http.HttpStreamContent fileContent = new Windows.Web.Http.HttpStreamContent(await file.OpenReadAsync());
fileContent.Headers.ContentType = new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("application/octet-stream");//image/png"
//  这样设置无效
//fileContent.Headers.ContentDisposition = new Windows.Web.Http.Headers.HttpContentDispositionHeaderValue("form-data");
//fileContent.Headers.ContentDisposition.Name = "Filedata";
#endregion
byte[] buffer = Encoding.UTF8.GetBytes(file.Name);
form.Add(fileContent, "Filedata", Encoding.UTF8.GetString(buffer, 0, buffer.Length));

client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0");
client.DefaultRequestHeaders.Add("Connection", "keep-alive");
Windows.Web.Http.HttpResponseMessage response = await client.PostAsync(new Uri(TotalInterfaceDocument.updateUserPicInterface), form).AsTask();
}

  

上传文件

标签:

原文地址:http://www.cnblogs.com/lj940306/p/4677882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!