【问题标题】:How to modify Content-Disposition Header when using .net WebClient FileUpload使用 .net WebClient FileUpload 时如何修改 Content-Disposition Header
【发布时间】:2011-02-23 15:33:23
【问题描述】:

使用 .net WebClient UploadFile 时,是否可以在多部分标头中手动设置name 属性?还是有其他方法可以解决这个问题?

-----------------------8cda1896efcd67f
Content-Disposition: form-data; **name="file"**; filename="Testfile.txt"
Content-Type: application/octet-stream

This is a Testfile.
-----------------------8cda1896efcd67f--

感谢您的任何建议!

【问题讨论】:

    标签: .net file-upload upload header webclient


    【解决方案1】:

    您可以通过以下方式使用 MultipartFormDataContent:

    MultipartFormDataContent form = new MultipartFormDataContent();
    string filename = @"Dir:\Testfile.txt"       
        , name = "file";
    byte[] bytes = System.IO.File.ReadAllBytes(filename);
    
    form.Add(new StringContent(name), "file");
    form.Add(new ByteArrayContent(bytes), "File", Path.GetFileName(filename));
    

    【讨论】:

      猜你喜欢
      • 2010-12-08
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      相关资源
      最近更新 更多