• 上传文件


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

      

  • 相关阅读:
    完美主义之我见
    职场-位置思维
    我的读书观
    人力资源是组织的第一战略资源-论基层员工
    积累是做成事情得唯一途径
    地理信息数据处理之我见
    word 之 插入删除空行
    OSMeteorTranslationAPI(百度,有道)对比
    CsharpOSMeteorCodeGenerator(Metero代码生成器)
    HtmlDOM 文档读取研究
  • 原文地址:https://www.cnblogs.com/lj940306/p/4677882.html
Copyright © 2020-2023  润新知