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

      

  • 相关阅读:
    Docker制作tomcat镜像,发布镜像
    DockerFile
    Docker容器数据卷
    Docker镜像
    Docker部署nginx,tomcat,es,可视化
    java 使用 poi 更新 ppt 中图表的数据
    require.js与IDEA的配合
    html中require.config 缓存问题
    mongodb 更新嵌套数组的值
    java poi ppt 接口的基本操作
  • 原文地址:https://www.cnblogs.com/lj940306/p/4677882.html
Copyright © 2011-2022 走看看