Problem with reCaptcha and .NET
Posted
by vtortola
on Stack Overflow
See other posts from Stack Overflow
or by vtortola
Published on 2010-05-26T09:49:00Z
Indexed on
2010/05/26
10:11 UTC
Read the original article
Hit count: 526
Hi,
I get this error with reCaptcha:
'Input error: response: Required field must not be blank
challenge: Required field must not be blank
privatekey: Required field must not be blank'
I'm sending the data via POST, so I don't understand what is going on. This is the code I use:
public static Boolean Check(String challenge, String response)
{
try
{
String privatekey = "7LeAbLoSAAAABJBn05uo6sZoFNoFnK2XKyF3dRXL";
String remoteip = HttpContext.Current.Request.UserHostAddress;
WebRequest req = WebRequest.Create("http://api-verify.recaptcha.net/verify");
req.Method = "POST";
using (StreamWriter sw = new StreamWriter(req.GetRequestStream()))
{
sw.Write("privatekey={0}&remoteip={1}&challenge={2}&response={3}", privatekey, remoteip, challenge, response);
sw.Flush();
}
String resultString = String.Empty;
String errorString = String.Empty;
using (StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream()))
{
resultString = sr.ReadLine();
errorString = sr.ReadLine();
}
Boolean b;
return Boolean.TryParse(resultString, out b) && b;
}
catch (Exception)
{
return false;
}
}
(Of course that'is not the correct private key :P)
I have no idea what the problem is about, I think I'm sending the data correctly, but that error says that apparently I'm not sending anything.
What could be the problem?
Cheers.
© Stack Overflow or respective owner