解决方法
This blog post详细说明如何使用
WebClient上传多个文件.
如果要同时在同一POST中同时上载表单域和文件,则无法使用WebClient,而是需要扩展.这是this article的摘录,解释需要什么:
the only option is to create a custom
implementation that conforms to
07003,07004 and the 07005 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-ed表单值发送到服务器.您要使用WebClient.UploadFile上传文件,或上述其中一个高级样本.