Problem with reCaptcha and .NET
- by vtortola
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.