I'm getting the following exceptions when getting the JSON response from reCAPTCHA:
SocketException (0x274c): 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 172.217.28.228:443
WebException: Unable to connect to the remote server
My server-side validation is as follows:
string secretKey = ConfigurationManager.AppSettings["Captcha.SecretKey"];
string url = "https://www.google.com/recaptcha/api/siteverify?secret=" + secretKey + "&response=" + response;
try
{
using (WebClient wc = new WebClient())
{
string jsonResponse = wc.DownloadString(url); //The exception happens here
CaptchaResponse captchaResponse = (new JavaScriptSerializer()).Deserialize<CaptchaResponse>(jsonResponse);
return Convert.ToBoolean(captchaResponse.Success);
}
}
catch (Exception ex)
{
throw ex;
}
Setting useDefaultCredentials to true in web.config solved the problem: