海康威视验证码查询18276248824验证码

HttpClient实现透过验证码查询 -
- ITeye技术网站
博客分类:
通过几天时间还是不能破解掉验证码,但是可以通过人工输入实现,这样并没有达到我想要的结果,但是还是记录下来,供大家参考,
private static Log log = LogFactory.getLog(HttpClientMail.class);
public static boolean query(String code,String key) {
boolean result =
String indexurl = "http://app./CheckPage.WebUI/Index.aspx?PURL=http%3a%2f%2fapp02.%2fWERMIS2.webui%2fWebPages%2fAIC%2fTradeSearch.aspx";
String sendurl = "http://app02./WERMIS2.webui/WebPages/AIC/TradeSearch.aspx";
String codeurl="http://app02./WERMIS2.webui/WebPages/WebRegUser/CheckCode.aspx";
// 需登陆后访问的 Url
HttpClient httpClient = new HttpClient();
log.debug("HttpClientLogin.getBroadbandNewNo(): 001: postMethod: ");
GetMethod getMethod = new GetMethod(indexurl);
//设置参数
NameValuePair[] data = {
new NameValuePair("PUTL", "http://app02./WERMIS2.webui/WebPages/AIC/TradeSearch.aspx"),
getMethod.setRequestHeader("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
getMethod.setRequestHeader("Accept-Encoding","gzip, deflate");
getMethod.setRequestHeader("Accept-Language", "zh-cn");
getMethod.setRequestHeader("Connection", "Keep-Alive");
getMethod.setRequestHeader("User-Agent", "Mozilla/4.0 ( MSIE 7.0; Windows NT 5.1; CIBA)");
getMethod.setQueryString(data);
httpClient.executeMethod(getMethod);
String getData = new String(getMethod.getResponseBody(),"UTF-8");
//-----------------------------访问首页,获取cookie----------------------------------------------
PostMethod postMethod = new PostMethod(sendurl);
//设置参数
NameValuePair[] data1 = {
new NameValuePair("hfIp", "121.15.133.155"),
postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
postMethod.setRequestHeader("Referer", indexurl);
postMethod.setRequestBody(data1);
httpClient.executeMethod(postMethod);
//获取cookie
Cookie[] cookies = httpClient.getState().getCookies();
String cookie = "";
for (Cookie c : cookies) {
cookie += c.toString() + ";";
getData = new String(postMethod.getResponseBody(),"UTF-8");
//-----------------------------获取验证码---------------------------------------------
GetMethod getMethod2 = new GetMethod(codeurl);
getMethod2.setRequestHeader("cookie",cookie);
httpClient.executeMethod(getMethod2);
code = savegif(getMethod2);
//------------------------关键字查询操作-------------------------
PostMethod postMethod1 = new PostMethod(sendurl);
//设置参数
NameValuePair[] data2 = {
new NameValuePair("__EVENTARGUMENT", ""),
new NameValuePair("__EVENTTARGET", "txtCheckCode"),
new NameValuePair("__LASTFOCUS", ""),
new NameValuePair("__VIEWSTATE", "Zb73qiSbM0qiPYhYIhU/u9IaFjmjc94zZ4OMyL7PGuex366gM1OHJNbPkuAZeWaZjHuqe923Vrjzn6mrgkcG3QUlepbFyvH4YoI24Kn18xBl+SqpQ6lY8hlKjkiPSJm5SleMQd3QDZ37d3qhGpCgOBvMmlrFt1y898uMkbco0whDJqxHRhlOiIIIhlQuOFvCZyq9+LzedTx5DQ+GmSUHgKJ0669O0LcFZMj5PofIl1bGbiRg5JiSjcq8hfovEQo843plLBzUKtdU/oEMvGcBABu19Zk20RpUicTEy56rWMhX1aGk0OcgEdFYieNhPYa0y5G0RjRWqvBXziV+SGUa2rio8EEqEcUoqRgQ3a1P/WIQGzMq8XofT/ACcsp+OWC2p2LguOQkhciqRBRns8I7mwWgiIAJf8pxJ26Jq3pozNECtomCg7jTAGfDftTMZv83gVTFchExwF7r1qCbfQc5Cs/mT1GgLtRMn4nvwOCCGUeCHCVCeyH8nLp16nIAXLpm00xdjbx2m8amwXzOu87tBbiqRejNCJES5e/VqSB42MT8bKs/Y5pxdC6mJ7fyW1RBruXo/1Q54JEANZKrA281OpzlrVks3/X3q4OOCaHrlXBt9znkEA9rgEjkXOF+4muGMgdjerzHZAnY1YKlo04fS7KPojZChQekj77yotEONp++1NU33yuxOSYfYOc="),
new NameValuePair("ScriptManager1", "upTopBtn|btnOnlyTradeName"),
new NameValuePair("btnOnlyTradeName","字号查重"),
new NameValuePair("txtCheckCode",code),
new NameValuePair("txtTradeName", URLDecoder.decode(key,"UTF-8")),
postMethod1.setRequestHeader("cookie",cookie);
postMethod1.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
postMethod1.setRequestBody(data2);
httpClient.getParams().setCookiePolicy(mons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY);
httpClient.executeMethod(postMethod1);
getData = new String(postMethod1.getResponseBody(),"UTF-8");
System.out.println(getData);
//解析html
if(getData.indexOf(URLDecoder.decode(key,"UTF-8"))&=0){
System.out.println("-------没有找到字号为:" + key +"的记录!");
String regex = "(&.+?&|&/.+?&| )+";
Pattern p = pile(regex);
String[] array = p.split(getData);
String res="";
for (String s : array) {
if ("".equals(s)) {
+= s +",";
String res_Ary[] = res.split(",");
for(String r:res_Ary){
if(r.indexOf(URLDecoder.decode(key,"UTF-8")) & 0){
System.out.println("您搜索的结果为:" +r);
}catch (Exception e) {
log.error("----------------------&&&key" + e + "-----------------------error");
public static String savegif(GetMethod getMethod) throws IOException {
/*String projectPath = HttpClientMail.class.getResource("").toString().replace("%20", " ").substring(6);
projectPath = projectPath.split("/WEB-INF/classes/")[0];
String excelPath = projectPath + "/file/2008sohu.gif";*/
String excelPath = "c:/code.jpg";
File storeFile = new File(excelPath);
FileOutputStream output = new FileOutputStream(storeFile);
//得到网络资源的字节数组,并写入文件
output.write(getMethod.getResponseBody());
output.close();
JFrame frame= new JFrame();
frame.setVisible(false);
frame.setBounds(100, 100, 100, 100);
frame.setLayout(new FlowLayout());
ImageIcon icon
= new ImageIcon(excelPath);
frame.add(new JLabel(icon));
frame.setVisible(true);
* 在控制台输入验证码
System.out.println("--------&&&&&请输入你看到的验证码:");
Scanner scr = new Scanner(System.in);
String ValidCode = scr.nextLine();
return ValidC
public static String GetRegex(String str, String rexString){
// 生成 Pattern 对象并且编译一个简单的正则表达式"Kelvin"
Pattern p = pile(rexString);
// 用 Pattern 类的 matcher() 方法生成一个 Matcher 对象
Matcher m = p.matcher(str);
String result = "";
if(m.find()){
result = m.group();
public static void main(String[] args) {
System.out.println("------------&&&&&请输入关键字:");
Scanner scr = new Scanner(System.in);
String key = scr.nextLine();
query("",URLEncoder.encode(key, "UTF-8"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
tanyongbing
浏览: 115542 次
来自: 深圳
liubin_ 写道地方法一般不超过80个字符
网站关键词
一般不超过100个字符
一般不超过200个字符
关键词排名分析
数据载入中,请稍候。
数据载入中,请稍候。
最近查询:
其他功能:
& 爱站网 版权所有
About Aizhan}

我要回帖

更多关于 苹果手机验证码查询 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信