Yesudass Moses
Yesudass Moses

Reputation: 1859

reCaptcha validation time out

I am trying to validate Google reCaptcha on my 1and1 hosted website. But when I execute this function on Server, It takes too long and my page is timed out. Can anyone point me out what is causing problem.

private string VerifyRecaptcha(string secret, string responseCode)
{
    WebRequest request = WebRequest.Create("https://www.google.com/recaptcha/api/siteverify");
    request.Method = "POST";
    string postData = "secret=" + secret + "&response=" + responseCode;
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = byteArray.Length;
    Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();
    WebResponse response = request.GetResponse();
     dataStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);
    string responseFromServer = reader.ReadToEnd();
    reader.Close();
    dataStream.Close();
    response.Close();
    return responseFromServer; 

}

Upvotes: 1

Views: 4649

Answers (1)

stevethethread
stevethethread

Reputation: 2524

This could be due to firewall issues on the server being able to communicate to the google domain. If you have a firewall, it may not be letting through calls to google, especially if it is filtering by IP address. Google has a range of IP's that you need to open up.

Upvotes: 1

Related Questions