【发布时间】:2015-06-02 07:27:02
【问题描述】:
我正在尝试制作一个与此页面具有相同功能的Android应用>>http://goo.gl/6pV6Zr
但我无法制作 HttpPost,也无法获得准确的验证码图像。
我正在尝试使用 jsoup 检索验证码。
try {
Document doc = Jsoup.connect(URL).get();
Element img = doc.select("img[id=siimage]").first();
String imgChar = img.attr("src");
captchaUrl = SECURE_IMAGE_URL + imgChar.substring(1);
InputStream input = new java.net.URL(captchaUrl).openStream();
bitmap = BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
}
并在 ImageView 中设置位图。
captchaImage.setImageBitmap(bitmap);
这是我的 HttpPost。
try{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(POST_URL);
ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("number", number));
nameValuePair.add(new BasicNameValuePair("message", message));
nameValuePair.add(new BasicNameValuePair("ct_captcha", captcha));
nameValuePair.add(new BasicNameValuePair("do", "send"));
nameValuePair.add(new BasicNameValuePair("apicode", API_CODE));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
if (resEntity != null){
String responseString = EntityUtils.toString(resEntity);
Log.v(TAG, "Response: " + responseString);
}
}catch (ClientProtocolException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
}
请指导我如何正确地..
- 检索页面上的验证码图像。
- 创建一个 post 方法。
【问题讨论】:
标签: android http response captcha