c# - 如何在 C# 中使用 webclient UploadFile、UploadValues 上传多个文件?

标签 c# webclient

如何在 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.

这里有三种实现,使用的方法略有不同,但都应该能够支持多部分表单数据:

WebClient.UploadValues不是为上传文件而设计的——而是用于将 POST 表单值发送到服务器。你想使用 WebClient.UploadFile上传文件,或上述高级示例之一。

关于c# - 如何在 C# 中使用 webclient UploadFile、UploadValues 上传多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2950292/

相关文章:

c# - 异常 : Specified cast is not valid

c# - 使用 C# 和 ASP.NET 从 Gmail/Hotmail/Yahoo 导入地址簿

c# - .Net DownloadFileTaskAsync 健壮的 WPF 代码

c# - 在 C# 中从 github 下载 zipball

wcf - 如何将用户凭据从 WebClient 传递到 WCF REST 服务?

c# - 域驱动应用程序中的集合过滤逻辑应该放在哪里?

c# - 是否可以将一个控件的事件处理程序 "steal"交给另一个控件?

c# - 如何运行一个 c# WinForm 应用程序实例?

c# - WebClient.DownloadFile 和正确的 url 操作已超时

c# - WebClient 运行 javascript