zoukankan      html  css  js  c++  java
  • 上传文件

    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();
    }
    

      

  • 相关阅读:
    windows下安装mysql(mysql-installer-community-5.6.10.1)
    mysql安装
    Full GC为什么那么慢?为什么老年代垃圾回收效率比新生代低很多?为什么Minor gc速度比Major GC慢?
    tomcat和HTTP(r equest response )
    response和request
    一次完整的Http请求过程
    servlet
    java泛型
    数据库索引的实现原理
    终端打印
  • 原文地址:https://www.cnblogs.com/lj940306/p/4677882.html
Copyright © 2011-2022 走看看