1

The URL works if I run it in a browser, so key and response are correct. However when I run the code locally, it throws a 503 error. Any ideas?

using System.Collections.Generic;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;


namespace ProjectM2.Shared
{
    public class ReCaptcha
    {
        public bool Success { get; set; }
        public List<string> ErrorCodes { get; set; }

        public static bool Validate(string encodedResponse)
        {
            if (string.IsNullOrEmpty(encodedResponse)) return false;

            var client = new System.Net.WebClient();

            var secret = ConfigurationManager.AppSettings["Google.ReCaptcha.Secret"];

            if (string.IsNullOrEmpty(secret)) return false;
            var googleReply = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret, encodedResponse));
            var reCaptcha = JsonConvert.DeserializeObject<ReCaptcha>(googleReply);

            return reCaptcha.Success;
        }
    }
}

  • Add following to beginning of the code : ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; – jdweng Jan 12 '21 at 15:21
  • Thank you for the prompt response, unfortunately, that did not resolve my problem. – Charles Flaherty Jan 12 '21 at 15:28
  • See following : https://developers.google.com/analytics/devguides/reporting/core/v3/errors – jdweng Jan 12 '21 at 15:32
  • Found that: https://developers.google.com/recaptcha & https://developers.google.com/recaptcha/old/docs/aspnet & [Google reCaptcha in Web API 2 c#](https://stackoverflow.com/questions/43327257/google-recaptcha-in-web-api-2-c-sharp) –  Jan 12 '21 at 15:35
  • I want to thank everyone for their responses. I've review all of your suggestions and I have not met with success. I still get the "The remote server returned an error: (503) Service Unavailable." error. – Charles Flaherty Jan 12 '21 at 16:34

1 Answers1

0

Solved. It turns out it was the web filter was the culprit. I moved my machine to a vlan without the web filter and the code works.

Thanks to everyone who took the time to read and answer my question.