使用webclient时的System.Net.Sockets.SocketException

时间:2015-06-25 10:56:57

标签: c# webclient socketexception

string uploadPath = "http://10.126.64.230/home/pi/Videos/";
WebClient webclient = new WebClient();
CredentialCache cc = new CredentialCache();
Uri uri = new Uri("http://10.126.64.230/pi");
NetworkCredential nc = new NetworkCredential();
nc.Domain = "root";
nc.UserName = "pi";
nc.Password = "posix";
cc.Add(
    uri,
"NTLM",
nc);
webclient.Credentials = cc;
//System.Text.Encoding.ASCII.GetString(responseArray);
bool cntrl = System.IO.File.Exists(uploadPath + this.FuplVideo.FileName);

if (cntrl)
{
    // fileName = uploadPath + this.FuplVideo.FileName + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + ext;
    // webclient.UploadFile(uploadPath, "POST", fullFilePath);
}
else
{
    webclient.UploadFile(uploadPath, "POST", fullFilePath);
}

我尝试将文件发送到与LAN连接的计算机。但我尝试使用不同版本的域代码,我得到了

  

" System.Net.Sockets.SocketException由于目标没有连接   机器拒绝"

每次

错误。你有什么建议我?

1 个答案:

答案 0 :(得分:0)

目标计算机有可能在您正在访问的端口上有防火墙规则。我猜这是端口80.尝试telnet到远程服务器,看看你是否得到了连接。如果你无法连接,那么它必须是防火墙问题