如何在android imageview中显示验证码图像?

时间:2022-09-04 08:19:17

I want to handle captcha image and display android imageview object.

我想处理验证码图像并显示android imageview对象。

Sample Captcha Registration Form

样品验证登记表

Captcha image download from url is not a solution.

从url下载验证码图像不是解决方案。

I've tried before, jsoup library,but I could not.

我之前尝试过,jsoup库,但我不能。

1 个解决方案

#1


1  

According to : How to display captcha in ImageView in Android.?

根据:如何在Android中的ImageView中显示验证码。

It's should be like that:

它应该是这样的:

private static final String FORM_TARGET = "http://www.indianrail.gov.in/cgi_bin/inet_pnstat_cgi.cgi";
private static final String INPUT_PNR = "lccp_pnrno1";
private static final String INPUT_CAPTCHA = "lccp_capinp_val";
private static final String INPUT_CAPTCHA_HIDDEN = "lccp_cap_val";

private void getHtml(String userPnr) {
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addTextBody(INPUT_PNR, userPnr); // users PNR code
    builder.addTextBody(INPUT_CAPTCHA, "123456");
    builder.addTextBody("submit", "Get Status");
    builder.addTextBody(INPUT_CAPTCHA_HIDDEN, "123456"); // values don't
                                                            // matter as
                                                            // long as they
                                                            // are the same

    HttpEntity entity = builder.build();

    HttpPost httpPost = new HttpPost(FORM_TARGET);
    httpPost.setEntity(entity);

    HttpClient client = new DefaultHttpClient();

    HttpResponse response = null;
    String htmlString = "";
    try {
        response = client.execute(httpPost);
        htmlString = convertStreamToString(response.getEntity().getContent());
                // now you can parse this string to get data you require.
    } catch (Exception letsIgnoreItForNow) {
    }
}

private static String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
    } catch (IOException ignoredOnceMore) {
    } finally {
        try {
            is.close();
        } catch (IOException manyIgnoredExceptions) {
        }
    }

    return sb.toString();
}

#1


1  

According to : How to display captcha in ImageView in Android.?

根据:如何在Android中的ImageView中显示验证码。

It's should be like that:

它应该是这样的:

private static final String FORM_TARGET = "http://www.indianrail.gov.in/cgi_bin/inet_pnstat_cgi.cgi";
private static final String INPUT_PNR = "lccp_pnrno1";
private static final String INPUT_CAPTCHA = "lccp_capinp_val";
private static final String INPUT_CAPTCHA_HIDDEN = "lccp_cap_val";

private void getHtml(String userPnr) {
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addTextBody(INPUT_PNR, userPnr); // users PNR code
    builder.addTextBody(INPUT_CAPTCHA, "123456");
    builder.addTextBody("submit", "Get Status");
    builder.addTextBody(INPUT_CAPTCHA_HIDDEN, "123456"); // values don't
                                                            // matter as
                                                            // long as they
                                                            // are the same

    HttpEntity entity = builder.build();

    HttpPost httpPost = new HttpPost(FORM_TARGET);
    httpPost.setEntity(entity);

    HttpClient client = new DefaultHttpClient();

    HttpResponse response = null;
    String htmlString = "";
    try {
        response = client.execute(httpPost);
        htmlString = convertStreamToString(response.getEntity().getContent());
                // now you can parse this string to get data you require.
    } catch (Exception letsIgnoreItForNow) {
    }
}

private static String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
    } catch (IOException ignoredOnceMore) {
    } finally {
        try {
            is.close();
        } catch (IOException manyIgnoredExceptions) {
        }
    }

    return sb.toString();
}