Nuevo Google Recaptcha con ASP.Net
Estoy intentando obtener el nuevoGoogle reCaptcha trabajando en mi proyecto ASP.NET y tengo problemas para que sea el nuevo "No soy un robot".
Tenía el viejo allí y después de investigar mucho en el sitio web developers.google.com, todo se ve igual (incluso me señalan una descarga del mismo dll - 1.0.5). Entonces, obtuve las nuevas claves y las puse y funciona, pero se parece a la antigua reCaptcha.
¿Alguien ha conseguido el nuevo para trabajar con su ASP.Net? ¿Qué me estoy perdiendo?
EDITAR:
Entonces, jugando en una aplicación de prueba y buscando en otros sitios web, descubrí que si creo una página como esta:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<form id="form1" runat="server" action="?" method="POST">
<div>
<div class="g-recaptcha" data-sitekey="My Public Key"></div>
<br/>
<asp:Button ID="Button1" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
Y luego, en mi código subyacente (Button1_Click), hago esto:
Dim Success As Boolean
Dim recaptchaResponse As String = request.Form("g-recaptcha-response")
If Not String.IsNullOrEmpty(recaptchaResponse) Then
Success = True
Else
Success = False
End If
losrecaptchaResponse
estará vacío o lleno dependiendo de si son un bot o no. El problema es que ahora necesito tomar esta respuesta y enviarla a google con mi clave privada para poder verificar que la respuesta no fue proporcionada por un bot, en mi código subyacente, pero no puedo entender cómo. Intenté esto (en lugar deSuccess = True
):
Dim client As New System.Net.Http.HttpClient()
client.BaseAddress = New Uri("https://www.google.com/recaptcha/")
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(New Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"))
Dim response As Net.Http.HttpResponseMessage = Await client.GetAsync("api/siteverify?secret=My Private key&response=" + recaptchaResponse)
If (response.IsSuccessStatusCode) Then
Dim CaptchResponse As ReCaptchaModel = Await response.Content.ReadAsAsync(Of ReCaptchaModel)()
Success = CaptchResponse.success
Else
Success = False
End If
Pero, no pude encontrar la manera de hacer que funcionen las cosas asíncronas y no puedo encontrar nada sobre quéReCaptchaModel
es decir, encontré otra forma de llamar a un servicio web y obtener una respuesta json e intenté esto en su lugar:
Dim request As Net.WebRequest = Net.WebRequest.Create("https://www.google.com/recaptcha/")
Dim Data As String = "api/siteverify?secret=My Private Key&response=" + recaptchaResponse
request.Method = "POST"
request.ContentType = "application/json; charset=utf-8"
Dim postData As String = "{""data"":""" + Data + """}"
'get a reference to the request-stream, and write the postData to it
Using s As IO.Stream = request.GetRequestStream()
Using sw As New IO.StreamWriter(s)
sw.Write(postData)
End Using
End Using
'get response-stream, and use a streamReader to read the content
Using s As IO.Stream = request.GetResponse().GetResponseStream()
Using sr As New IO.StreamReader(s)
'decode jsonData with javascript serializer
Dim jsonData = sr.ReadToEnd()
Stop
End Using
End Using
Pero, esto solo me da el contenido de la página web enhttps://www.google.com/recaptcha. No es lo que quiero. losPágina de Google no es muy útil y estoy atascado sobre dónde ir. Necesito ayuda ya sea llamando al servicio de verificación de Google o si alguien ha encontrado otra forma de hacerlo desde ASP.NET.