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

来源:互联网 发布:我的世界java诺基亚版 编辑:程序博客网 时间:2024/04/30 12:51

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

  没有验证码的登陆很好办,但是现在的网站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();        }    }


0 0
原创粉丝点击