码迷,mamicode.com
首页 > 其他好文 > 详细

验证码识别技术(一)

时间:2015-08-14 15:35:44      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

一,图片下载方法

如果在源文件中,验证码是img形式,就非常好下载处理了。这里就不在陈述了,目前好多验证码都是数据流形式,需要编程处理,首先,要获取验证码的地址,例如:地址为http://aaa.bbb.ccc/code

public static void GetURL() throws ClientProtocolException, IOException {

        // 1,获取图片
        @SuppressWarnings("deprecation")
        HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost
= new HttpPost("http://aaa.bbb.ccc/code");//图片的URL httpPost.setHeader(CommonConst.UserAgent, CommonConst.HttpAgent); httpPost.setHeader("Cache-Control", "max-age=0"); httpPost.setHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); httpPost.setHeader("Accept-Encoding", "gzip,deflate,sdch"); httpPost.setHeader("Accept-Language", "en-US,en;q=0.8"); httpPost.setHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3"); httpPost.setHeader("Accept-Encoding", "gzip,deflate,sdch"); HttpResponse response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); byte[] imgArray = new byte[200 * 60];//下载图片后,看图片的大小 if (entity != null) { java.io.InputStream instreams = entity.getContent(); instreams.read(imgArray); httpPost.abort(); } // 2,保存图片 mWriterPicture("E:\\testc\\1原始验证码\\a.jpg", imgArray); }
// 写入图片
    public static void mWriterPicture(String newFileName, byte[] b)throws IOException {
        try {
            File file = new File(newFileName);
            FileOutputStream fStream = new FileOutputStream(file);
            fStream.write(b);
            fStream.close();
            System.out.println("图片创建成功    " + b.length);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

 

验证码识别技术(一)

标签:

原文地址:http://www.cnblogs.com/nyist2007/p/4729882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!