【问题标题】:getting captcha image from webpage [android]从网页获取验证码图像 [android]
【发布时间】: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();
    }
}

请指导我如何正确地..

  1. 检索页面上的验证码图像。
  2. 创建一个 post 方法。

【问题讨论】:

    标签: android http response captcha


    【解决方案1】:

    替换:-

    • 这个-Element img = doc.select("img[id=siimage]").first();

    • 这个-Element img = doc.select("img#siimage").first();

    【讨论】:

      猜你喜欢
      • 2013-07-03
      • 1970-01-01
      • 2013-07-30
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多