Error : The remote server returned an error: (417) Expectation Failed. (ASP.NET 2.0 / C# )

732 views
Skip to first unread message

Ahsan

unread,
Jan 8, 2008, 5:36:37 AM1/8/08
to reCAPTCHA
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

reCAPTCHA Support

unread,
Jan 8, 2008, 10:56:09 AM1/8/08
to reca...@googlegroups.com
You need to set:
request.ProtocolVersion = HttpVersion.Version10;
This prevents asp.net from requesting the 100 continue header.

- Ben

                    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



--
reCAPTCHA: stop spam, read books
http://recaptcha.net

reCAPTCHA Support

unread,
Jan 8, 2008, 10:56:55 AM1/8/08
to reca...@googlegroups.com
Also, you should look at using:

http://recaptcha.googlecode.com/svn/trunk/recaptcha-plugins/dotnet/

As that is a well tested asp.net plugin.

On 1/8/08, Ahsan <ahsan...@gmail.com> wrote:
                    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

Ahsan

unread,
Jan 9, 2008, 2:23:31 AM1/9/08
to reCAPTCHA
Thanx for replying and helping.
Although, i have one more question.
If i am using the reCaptcha.dll , can i still customize the theme and
appearance of the reCaptcha.
Regards,
Ahsan


On Jan 8, 8:56 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> Also, you should look at using:
>
> http://recaptcha.googlecode.com/svn/trunk/recaptcha-plugins/dotnet/
>
> As that is a well tested asp.net plugin.
>
> > while ((line = reader.ReadLine()) != null)
Reply all
Reply to author
Forward
0 new messages