我试图创建一个与此页面具有相同功能的Android应用程序>> http://goo.gl/6pV6Zr
但是我无法让HttpPost工作,我无法获得精确的Captcha图像。
我试图使用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();
}
}
请指导我如何以正确的方式......
答案 0 :(得分:0)
替换: -
Element img = doc.select("img[id=siimage]").first();
与
Element img = doc.select("img#siimage").first();