【问题标题】:System.Net.Sockets.SocketException while using webclient [duplicate]使用 webclient 时出现 System.Net.Sockets.SocketException [重复]
【发布时间】:2015-09-11 22:40:07
【问题描述】:
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 因为目标没有连接 机器拒绝”

每次都出错。你有什么建议?

【问题讨论】:

  • 如何使用 System.IO 读取 httpPath? bool cntrl = System.IO.File.Exists(uploadPath + this.FuplVideo.FileName)?如果其 netqork 使用 UNC:\\10.126.64.230\home\pi\Videos\
  • 我会在修复此错误后将其删除。

标签: c# webclient socketexception


【解决方案1】:

目标机器有可能在您访问的端口上有防火墙规则。我猜这是端口 80。尝试 telnet 到远程服务器,看看是否有连接。如果无法连接,那一定是防火墙问题

【讨论】:

  • 我可以将文件复制到机器,但无法通过代码访问。
  • 转到命令行并尝试:c:/telnet 10.126.64.230 80
  • 是的。显然,防火墙规则已经到位。要确认尝试使用您的浏览器导航到10.126.64.230/home/pi/Videos 并查看您得到什么。如果您有提琴手,您也可以尝试使用提琴手进行连接。将您收到的错误粘贴到此处。
  • 当我尝试那台机器时,问我用户名和密码。在我输入之后,它用 10.126.64.230/home/pi/Videos 这个搜索重定向了我的谷歌。
  • 在浏览器中使用该链接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-29
  • 1970-01-01
  • 2020-07-31
  • 2015-05-02
  • 2013-11-21
  • 2014-07-09
相关资源
最近更新 更多