网页版的模拟登陆有验证码的网站

   模拟登陆就是向登陆链接提交表单。

  没有验证码的登陆很好办,但是现在的网站10个里8个有验证码。验证码识别算法正确率又很低。

如果是脚本模拟登陆的话直接把验证码拉回来人工识别,网页版的话如果把别的网站的验证码拉回来再显示在自己的网站上,多人访问的话就会造成验证码和sessionId不匹配而登不上。所以直接把对方的验证码直接写到我的页面上。

用到apache httpclient包,用ImageIO读取在写入。

方案:

public void getYzm(HttpServletResponse respons){
        HttpGet hg=new HttpGet(yzmUrl+Math.random());
        try {
            CloseableHttpResponse response=client.execute(hg);
            HttpEntity he=response.getEntity();
            InputStream is=he.getContent();
            OutputStream os=respons.getOutputStream();
            BufferedImage bi=ImageIO.read(is);
            respons.setHeader("Cache-Control", "no-cache");
            respons.setHeader("Pragma", "no-cache");
            respons.setDateHeader("Expires", 0);
            respons.setContentType("image/gif");
            ImageIO.write(bi,"gif",os);
            is.close();
            os.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }


原文地址:https://www.cnblogs.com/A-yes/p/9894214.html