如何在 C# 中使用 webclient UploadFile、UploadValues 上传多个文件?
最佳答案
This blog post详细说明如何使用 WebClient 上传多个文件.
如果您想在同一个 POST 中同时上传表单字段和文件,则不能按原样使用 WebClient,而是需要对其进行扩展。这是 this article 的摘录解释需要什么:
the only option is to create a custom implementation that conforms to rfc1867, rfc2388 and the W3C multipart/form-data specification that will enable file upload with additional form fields and exposes control of cookies and headers.
这里有三种实现,使用的方法略有不同,但都应该能够支持多部分表单数据:
- http://www.codeproject.com/Articles/72232/Csharp-File-Upload-with-form-fields-cookies-and-he.aspx
- http://www.codeproject.com/KB/cs/uploadfileex.aspx
- http://aspnetupload.com/Upload-File-POST-HttpWebRequest-WebClient-RFC-1867.aspx
WebClient.UploadValues不是为上传文件而设计的——而是用于将 POST 表单值发送到服务器。你想使用 WebClient.UploadFile上传文件,或上述高级示例之一。
关于c# - 如何在 C# 中使用 webclient UploadFile、UploadValues 上传多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2950292/