C# 连接尝试失败,因为连接方在一段时间后没有正确响应或连接的主机未能响应

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12758727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 00:20:44  来源:igfitidea点击:

A connection attempt failed because the connected party did not properly respond after a period of time or connected host has failed to respond

c#windows-serviceswebclientwindows-serverwebclient-download

提问by Laila

I'm developing a windows service, that downloads images from a specific URL. The service runs correctly on my computer but when I install it in the server it does not download the image and it gives the following error:

我正在开发一个 Windows 服务,它从特定的 URL 下载图像。该服务在我的计算机上正常运行,但是当我将其安装在服务器中时,它不会下载图像并出现以下错误:

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 212.100.220.117:80

at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)

at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)

--- End of inner exception stack trace ---

at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) at System.Net.WebClient.DownloadData(Uri address) at System.Net.WebClient.DownloadData(String address)

System.Net.WebException: 无法连接到远程服务器 ---> System.Net.Sockets.SocketException: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机而建立连接失败未能响应 212.100.220.117:80

在 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)

在 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)

--- 内部异常堆栈跟踪结束 ---

在 System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) at System.Net.WebClient.DownloadData(Uri address) at System.Net.WebClient.DownloadData(String address)

What might be causing the error and how can I resolve it? I read this page: http://support.microsoft.com/kb/318140

什么可能导致错误,我该如何解决?我读了这个页面:http: //support.microsoft.com/kb/318140

but I'm not sure if this is the problem, and if it is what proxy should I write in the config. Asking you for your advice.

但我不确定这是否是问题所在,如果是我应该在配置中写入什么代理。征求你的意见。

Thank you,

谢谢,

采纳答案by Laila

I found the answer. I was trying to access the public address "http://mywebsite.com/images/" from the server. Instead of that I used the local IP of the server hosted the website and it's now working.

我找到了答案。我试图从服务器访问公共地址“ http://mywebsite.com/images/”。相反,我使用了托管网站的服务器的本地 IP,它现在可以正常工作了。

回答by Kedar Ghadge

In this case it might be possible that port 80 is not open. Create an inbound and outbound rule in firewall setting to open port 80. Still, if the issue exists try with disabling the antivirus, It might be possible that antivirus is blocking the port.

在这种情况下,端口 80 可能未打开。在防火墙设置中创建入站和出站规则以打开端口 80。不过,如果存在问题,请尝试禁用防病毒软件,防病毒软件可能会阻止该端口。