Hi, I use the WebClient to read web pages from my asp.net application. For that, I used WebClient with webClient.DownloadString method. I get the following exection each time I try to connect:
InnerException = {"A connection attempt failed because the connected party did not respond properly after a certain amount of time or an established connection failed because the login host did not respond 160.119.189.95:80"}; Message = "Can not connect
to the remote server"
Is there a solution to this problem?
Code example:
WebClient client = new WebClient();
try{
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
string s = client.DownloadString("https://en.wikipedia.org/wiki/Malaria");
//other things here
}catch (Exception e)
{}
Your code is fine and working. A timeout can happen.
But there is something not clear on your provided info.
Exception say 160.119.189.95:80, this is an HTTP not HTTPS, at this place there is an index.html with Bad file descriptor
Your code shows https://en.wikipedia.org, which not resolves to 160.119.189.95
I have tested your code in my computer but I could get response successfully.
Are you sure your computer could connect to the server?
Have you tried to directly paste the address in browser to see whether you could get the response?
If the network between your computer and your remoter server is ok, this may have something to do with proxy setting of your web.config,you could disable it.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
I do not understand when you say : "at this place there is an index.html with Bad file descriptor
Your code shows https://en.wikipedia.org, which not resolves to 160.119.189.95".
what does it mean? Because I do not always work. While the link is easily accessible on the browser
@Ackerly Xu, you right, but only if there is a way to bypass network proxy
@bokokibiti
Pay attention to InnerMessage
bokokibiti
InnerException = {"A connection attempt failed because the connected party did not respond properly after a certain amount of time or an established connection failed because the
login host did not respond 160.119.189.95:80"}; Message = "Can not connect to the remote server"
Is 160.119.189.95 a proxy server with authentication?
To me seems it is. In this case you have to set Proxy data on webclient before call url
Try Dim myProxyIP as string = "use ip address of your proxy" Dim myProxyPort as integer = "use port of your proxy" Dim myUser as string = "user name here" Dim myPwd as string = "user password here"
Dim myProxy As System.Net.WebProxy = New System.Net.WebProxy(myProxyIP, myProxyPort) With {.Credentials = New System.Net.NetworkCredential(myUser, myPwd)}
Dim myClient As New System.Net.WebClient
myClient.Proxy = myProxy
myClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
Dim myString As String = myClient.DownloadString("https://en.wikipedia.org/wiki/Malaria")
Catch ex As Exception
End Try
Member
2 Points
23 Posts
Failed to connect to remote server with WebClient.DownloadString () method
Feb 17, 2019 08:39 AM|bokokibiti|LINK
Hi, I use the WebClient to read web pages from my asp.net application. For that, I used WebClient with webClient.DownloadString method. I get the following exection each time I try to connect:
InnerException = {"A connection attempt failed because the connected party did not respond properly after a certain amount of time or an established connection failed because the login host did not respond 160.119.189.95:80"}; Message = "Can not connect to the remote server"
Is there a solution to this problem?
Code example:
Participant
1061 Points
665 Posts
Re: Failed to connect to remote server with WebClient.DownloadString () method
Feb 17, 2019 11:33 AM|jzero|LINK
Your code is fine and working. A timeout can happen.
But there is something not clear on your provided info.
Exception say 160.119.189.95:80, this is an HTTP not HTTPS, at this place there is an index.html with Bad file descriptor
Your code shows https://en.wikipedia.org, which not resolves to 160.119.189.95
Contributor
3500 Points
1300 Posts
Re: Failed to connect to remote server with WebClient.DownloadString () method
Feb 18, 2019 03:22 AM|Ackerly Xu|LINK
Hi bokokibiti,
I have tested your code in my computer but I could get response successfully.
Are you sure your computer could connect to the server?
Have you tried to directly paste the address in browser to see whether you could get the response?
If the network between your computer and your remoter server is ok, this may have something to do with proxy setting of your web.config,you could disable it.
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
2 Points
23 Posts
Re: Failed to connect to remote server with WebClient.DownloadString () method
Feb 18, 2019 11:32 AM|bokokibiti|LINK
Hi jzero.
I do not understand when you say : "at this place there is an index.html with Bad file descriptor
Your code shows https://en.wikipedia.org, which not resolves to 160.119.189.95".
what does it mean? Because I do not always work. While the link is easily accessible on the browser
Member
2 Points
23 Posts
Re: Failed to connect to remote server with WebClient.DownloadString () method
Feb 18, 2019 11:45 AM|bokokibiti|LINK
Thank you for your answer Ackerly Xu.
Are you sure your computer could connect to the server? Yes
I add the code in the web.config. it does not always work
Participant
1061 Points
665 Posts
Re: Failed to connect to remote server with WebClient.DownloadString () method
Feb 18, 2019 01:14 PM|jzero|LINK
@Ackerly Xu, you right, but only if there is a way to bypass network proxy
@bokokibiti
Pay attention to InnerMessage
Is 160.119.189.95 a proxy server with authentication?
To me seems it is. In this case you have to set Proxy data on webclient before call url
Member
2 Points
23 Posts
Re: Failed to connect to remote server with WebClient.DownloadString () method
Feb 18, 2019 01:36 PM|bokokibiti|LINK
OK I try to follow your method