gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:49:17 25 4
gpt4 key购买 nike

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

Sample Captcha Registration Form

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

我以前试过,jsoup图书馆,但我不能。

最佳答案

根据 : How to display captcha in ImageView in Android.?

应该是这样的:

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();
}

关于android - 如何在 android imageview 中显示验证码图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24480087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com