Hi,
I am having trouble setting recaptcha manually, I always get invalid-
request-cookie as a response, this is what I use:
I am working on it on my local machine that has this site on
127.0.0.1:
http://nationalgrid-uk.ektron.com, so that is the site I
registered.
This is the code that communicates with your servers:
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public bool IsValid(string challenge, string response)
{
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "privatekey={0}&remoteip{1}&challenge{2}
&response{3}";
postData = string.Format(postData, "6Lf_s9ESAAAAAOSlD2-
wpVtsuhe8Rb2DoivwWqUK", HttpContext.Current.Request.UserHostAddress,
challenge, response);
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("
http://www.google.com/recaptcha/api/
verify");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse webresponse =
(HttpWebResponse)myRequest.GetResponse();
StreamReader loResponseStream = new
StreamReader(webresponse.GetResponseStream());
string webResponse = loResponseStream.ReadToEnd();
return true;
}
And this is the jquery ajax call to that method:
function setQuestion() {
var challenge = Recaptcha.get_challenge();
var response = Recaptcha.get_response();
alert(challenge);
alert(response);
$.ajax({
type: "GET",
url: "/Source/Ajax/Recaptcha.asmx/IsValid",
cache: false,
contentType: "application/json; charset=utf-8",
data: { challenge: JSON.stringify(challenge),
response: JSON.stringify(response) },
dataType: "json",
success: handleHtml
});
}
Thank you for your help.