我正在尝试使用C#将我的Windows应用程序中的文件上传到特定的文件夹中。但是,我得到了一个例外:
“WebClient请求期间发生异常”。
这是我的代码:
for (int i = 0; i < dtResponseAttach.Rows.Count; i++)
{
string filePath = dtResponseAttach.Rows[i]["Response"];
WebClient client = new WebClient();
NetworkCredential nc = new NetworkCredential();
Uri addy = new Uri("http://192.168.1.4/people/Attachments/");
client.Credentials = nc;
byte[] arrReturn = client.UploadFile(addy, filePath);
Console.WriteLine(arrReturn.ToString());
}
这种例外可能是什么原因?
答案 0 :(得分:0)
如果你没有填写NetworkCredential
,那么我很确定你不应该附上一个。
另一种可能性是,您正在通过代理,并需要添加代理详细信息:
WebProxy p = new WebProxy ("192.168.10.01", true);
p.Credentials = new NetworkCredential ("username", "password", "domain");
using (WebClient wc = new WebClient())
{
wc.Proxy = p;
...
}