太好了,我忘了怎么做贴子了
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";
byte[] byteArray = Encoding.UTF8.GetBytes(String.Format("privatekey={0}&remoteip={1}&challenge={2}&response={3}", privatekey, remoteip, challenge, response));
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = byteArray.Length;
req.GetRequestStream().Write(byteArray, 0, byteArray.Length);
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;
}
}