reCAPTCHA connection timeout error on 1and1 IONOS hosting
Got this error while validating the reCAPTCHA with google on submission of a form in my asp.net mvc website hosted on 1and1 IONOS windows hosting server.
> Error: 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.
If you see the same error on your 1and1 IONOS hosting environment while connecting to external APIs then this might be the post you are looking for.
I have ran the same website on my local machine and it worked perfect. Even I was able to submit the form, validate reCAPTCHA with google API and the data was being saved perfectly. When i move the same code to the hosting environment, I see this error.
This error is a connection timeout error. Seems like the connection to the Google servers for reCAPTCHA validation is not successful for some reason. After some research I found that the connection to the google reCAPTCHA API servers is blocked by the 1and1 IONOS hosting network firewall. This is done as a security measure to disallow any direct calls to externals network servers. To resolve this, there needs to be proxy provided by the hosting service which can connect to the google servers. I have got the below proxy server details and tried it. It worked!!
Add the below proxy settings to the web.config file. This would be applied to all the external web requests in your code/website.
<proxy usesystemdefault = "false" bypassonlocal="false" proxyaddress="http://ntproxyus.lxa.perfora.net:3128"/>
If you like to apply this proxy setting only to a particular web request, then instead of adding these lines in web.config file, just add the proxy server (
http://ntproxyus.lxa.perfora.net:3128) to the web request directly in the code. Here are the diferent ways of adding proxy setting in C# - Different ways of connecting through Proxy in c#
Hope this helps. Please do comment your thoughts.