如何使用Web客户端UploadFile,UploadValues​​在C#中上传多个文件? [英] How to upload multiple files using webclient UploadFile, UploadValues in C#?

查看:207
本文介绍了如何使用Web客户端UploadFile,UploadValues​​在C#中上传多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Web客户端UploadFile,UploadValues​​在C#中上传多个文件

How to upload multiple files using webclient UploadFile, UploadValues in C#?

推荐答案

This博客文章的细节究竟如何使用上传多个文件<一个HREF =htt​​p://msdn.microsoft.com/en-us/library/system.net.webclient.aspx> WebClient的。

This blog post details exactly how to upload multiple files using WebClient.

如果你想同时上传表单字段,并在同一职位的文件,你不能使用Web客户端作为-is--相反,它需要被延长。下面是这篇文章解释需要什么:

If you want to upload both form fields and a file in the same POST, you can't use WebClient as-is-- instead it will need to be extended. Here's an excerpt from this article explaining what is needed:

唯一的选择是创建符合
定制
实施的 RFC1867 rfc2388 W3C
的multipart / form-data的
规范,
将启用与
附加表单字段文件上传,并公开cookie和头的
控制。

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.

下面有三种实现方式,使用稍有不同的方法,但都应该努力使多部分表单数据:

Here are three implementations, using slightly different approaches, but all should work to enable multi-part form data:

  • 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 不是设计用来上传files-- .UploadValues​​,而不是它的用于发送POST-ED表单数据到服务器。要使用 WebClient.UploadFile 上传文件,或之一上述先进的样品。

WebClient.UploadValues is not designed to upload files-- instead it's used to send POST-ed form values to the server. You want to use WebClient.UploadFile to upload files, or one of the advanced samples above.

这篇关于如何使用Web客户端UploadFile,UploadValues​​在C#中上传多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆