如何在Java中使用reCAPTCHA Ver 2?

kha*_*eeb 3 java recaptcha

我正在尝试在我的Java Web应用程序中实现reCAPTCHA ver 2.为了验证用户的响应,我需要g-recaptcha-response根据这里的教程获取reCAPTCHA发布到我的服务器的值.但Java不允许带有连字符的变量名.我如何获得这个价值?

Ste*_*n C 6

You don't need a variable called g-recaptcha-response. That is the name of a parameter in an HTTP POST request. You simply retrieve the parameter value from the request, and store it in a Java variable ... whose name is whatever you want it to be.

 String str = request.getParameter("g-recaptcha-response");
Run Code Online (Sandbox Code Playgroud)

Here are the javadocs for the ServletRequest class.