代码之家  ›  专栏  ›  技术社区  ›  sharptooth

用httpput上传的文件在开头和结尾都有额外的数据

  •  1
  • sharptooth  · 技术社区  · 14 年前

    我在IIS中创建了一个虚拟目录,并在程序中执行以下代码:

    System.Net.WebClient webClient = new System.Net.WebClient();
    webClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
    webClient.UploadFile( "http://localhost/Exchange/file.jpg", "PUT", localPathToMyFile );
    

    -----------------------8ccfabf2a995855
    Content-Disposition: form-data; name="file"; filename="file.jpg"
    Content-Type: application/octet-stream
    //file contents goes here
    -----------------------8ccfabf2a995855
    

    这些额外的数据从何而来?我该怎么做才能使它不出现,但文件是按原样上传的?

    2 回复  |  直到 14 年前
        1
  •  2
  •   corvuscorax    14 年前

    额外的数据来自HTTP协议,请参阅 here here

        2
  •  2
  •   jgauffin    14 年前

    这就是HTML表单的上传方式。

    http://www.15seconds.com/issue/001003.htm

    http://www.faqs.org/rfcs/rfc2388.html

    如何保存文件?