Hi there,
I am using recaptcha in my application built in
asp.net 2.0 / C #.
Recaptcha has been showing a random behavior so far.
Some times, it works as expected.
Some times it doens't give any respone (i am using HttpWebResponse).
Some times it through the error : "The remote server returned an
error: (417) Expectation Failed."
Here is the code :
//============================
private String PostMe()
{
string challange =
Server.UrlDecode(Request.Params["captchaCodeChallange"]);
string response =
Server.UrlDecode(Request.Params["captchaCodeResponse"]);
string poststring =
String.Format("privatekey={0}&remoteip={1}&challenge={2}&response={3}",
"<myprivatekey>", Request.ServerVariables["REMOTE_ADDR"], challange,
response);
return GetResponseString("
http://api-verify.recaptcha.net/
verify", poststring);
}
private String GetResponseString(string url, string
poststring)
{
try
{
string strRecaptchaResult = String.Empty;
HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-
urlencoded";
byte[] bytedata =
Encoding.UTF8.GetBytes(poststring);
httpRequest.ContentLength = bytedata.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpRequest.GetResponse();
Stream responseStream =
httpWebResponse.GetResponseStream();
Int16 counter = 0;
using (StreamReader reader = new
StreamReader(responseStream, System.Text.Encoding.UTF8))
{
string line;
while ((line = reader.ReadLine()) != null)
{
if(counter==0)
{
strRecaptchaResult = line;
}
counter++;
}
}
}
catch (Exception excp)
{
return "false";
}
return strRecaptchaResult ;
}
//============================
Can any one help me decipher this mystery ? :)
Is it some how related to how frequently you request for another
captcha code?
Any help would be greatly appreciated.
Regards,
Ahsan