C# 将文件上载到服务器
我正在尝试使用C#将文件从Windows应用程序上载到服务器的特定文件夹中。但是,我有一个例外: “WebClient请求期间发生异常” 这是我的密码:C# 将文件上载到服务器,c#,exception,webclient,file-upload,C#,Exception,Webclient,File Upload,我正在尝试使用C#将文件从Windows应用程序上载到服务器的特定文件夹中。但是,我有一个例外: “WebClient请求期间发生异常” 这是我的密码: for (int i = 0; i < dtResponseAttach.Rows.Count; i++) { string filePath = dtResponseAttach.Rows[i]["Response"]; WebClient client = new WebClient(); NetworkCredenti
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());
}
for(int i=0;i
出现此异常的原因可能是什么?如果您没有填写
网络凭据,那么我很确定您不应该附加此凭据
另一种可能性是,您正在通过代理,需要添加代理详细信息:
WebProxy p = new WebProxy ("192.168.10.01", true);
p.Credentials = new NetworkCredential ("username", "password", "domain");
using (WebClient wc = new WebClient())
{
wc.Proxy = p;
...
}
您是否查看过InnerException或查询过异常流以获取更多信息。是的,我同意。“WebClient请求期间发生异常”并没有告诉我们全部情况