Hello everyone,
I have been trying to implement recaptcha v2 to one of my JSP web application. Below is the code
<%
String your_private_key = "xxxxxxxxxxxxxxxx";
String USER_AGENT = "Mozilla/5.0";
String gRecaptchaResponse = request.getParameter("g-recaptcha-response");
System.out.println("***** gRecaptchaResponse ***** : "+gRecaptchaResponse);
System.out.println("***** getRemoteAddr ***** : "+request.getRemoteAddr());
URL url = new URL("https://www.google.com/recaptcha/api/siteverify?secret=" + your_private_key + "&response=" + gRecaptchaResponse + "&remoteip=" + request.getRemoteAddr());
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
// add reuqest header
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer responseBuffer = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
responseBuffer.append(inputLine);
}
in.close();
String response2 = responseBuffer.toString();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("\nSending 'POST' request to URL : " + response2);
if (response2.contains("true"))
{
System.out.println("***** Sucess ***** ");
}
else
{
System.out.println("***** Failure ***** ");
}
%> Every thing works fine BUT when I print the response2 string it gives
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style type="text/css">html,body{height:100%;padding:0;margin:0;}.oc{display:table;width:100%;height:100%;}.ic{display:table-cell;vertical-align:middle;height:100%;}div.msg{display:block;border:1px solid #30c;padding:0;width:500px;font-family:helvetica,sans-serif;margin:10px auto;}h1{font-weight:bold;color:#fff;font-size:14px;margin:0;padding:2px;text-align:center;background: #30c;}p{font-size:12px;margin:15px auto;width:75%;font-family:helvetica,sans-serif;text-align:left;}</style><title>The URL you requested has been blocked</title></head><body><div class="oc"><div class="ic"><div class="msg"><h1>The URL you requested has been blocked</h1><p>The page you have requested has been blocked, because the URL is banned.<br /><br />URL = www.google.com/<br /></p></div></div></div></body></html>2BuhiF%2FQUpC21zrZMLXS%2Fzev0xYSRhG2CAwlIaAzUkBZpqeR8LQCS5UM%3D&ctl00%24MainContent%24txtUsername=1027797149&ctl00%24MainContent%24txtPassword=4243522&ctl00%24MainContent%24btnLogin=%D8%AF%D8%AE%D9%88%D9%84��< ����>r��-?� L which says
The URL you requested has been blocked
The page you have requested has been blocked, because the URL is banned.
URL = www.google.com/
And that is why I'm unable to verify the captcha response.
Can anyone tell me what is happening?
Any type of help is appreciated.
Thanks.