0

我正在尝试使用 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());
}

此异常的原因可能是什么?

4

1 回答 1

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;
  ...
}
于 2009-03-24T07:49:36.680 回答