我想用 Java 创建注册申请,然后我想将信息提交到网站.这只是实验,因此注册信息(例如用户名、密码)将与 GET 请求一起提交.但是,我想将验证码与注册集成,我想将它显示在 Jframe 上并将答案与其他数据一起提交.我不知道如何获取验证码图像,然后提交数据.我也想使用新的 reCaptcha(它要求你选择食物).任何想法如何做到这一点?
I want to create application for registration in Java, then I want to submit the information to a website. This is only experiment so the information for the registration(e.g username, password) will be submit with GET request. However I want to integrate captcha with the registration and I want to display it on the Jframe and submit the answer along side with the other data. I have no idea how to get the captcha image, and then submit the data. Also I think to use the new reCaptcha(where it ask you to select foods). Any ideas how to do this?
我知道如何使用 JLabel 显示图像,我还能够找到一种提取它的方法 Get验证码会话的图像.现在我想知道如何发送响应.
I know how to display the image with JLabel, I also was able to find a way to extract it Get image for captcha session .Now i'm wondering how to send the response.
推荐答案要发送响应,您可能需要来自服务器的会话 ID,客户端响应然后只需向服务器发送包含这两个值的 GET 请求
To send a response you will probably need a Session ID from the server and the clients answer then just send a GET request to the server with both of the values
public void getMethod() throws IOException { String userAgent = "Java/" + Runtime.class.getPackage().getImplementationVersion(); //The server will need to know what "question" we are answering so it sent us the captha and a sesion ID //example is just a random one you will need to figure out how to get a sesion id String captchaSesionParam = "captchaSesionID="; String captchaSesionID = UUID.randomUUID().toString(); //user has completed captha client side here is their answer String queryParam = "answer="; String answer = "blah blah answer"; String urlString = "127.0.0.1/?" + queryParam + URLEncoder.encode(answer, "UTF-8") + "&" + captchaSesionParam + URLEncoder.encode(captchaSesionID, "UTF-8"); URL url = new URL(urlString); //Open a HTTPS connection to the URL HttpURLConnection con = (HttpURLConnection) url.openConnection(); //set request method to GET con.setRequestMethod("GET"); //set user agent to our agent (by default I believe that this is 'Java/Version') con.setRequestProperty("User-Agent", userAgent); //print out debug info about request method and url System.out.println(con.getRequestMethod() + " URL : " + url); int responseCode = con.getResponseCode(); System.out.println("Server response code: " + responseCode); try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));) { String line; List<String> lines = new ArrayList<String>(); while ((line = in.readLine()) != null) { lines.add(line); } //parse lines received from server to see if the captcha was (in)correct //print lines for debug for(String l : lines) { System.out.println(l); } } }更多推荐
在 Jframe 中显示验证码
发布评论