39,084
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
HttpClient h = new HttpClient();
String sessionID = "";
try {
GetMethod get = new GetMethod("http://shop.gkyc.cn/login.jsp");
h.executeMethod(get);
Cookie[] cookie = h.getState().getCookies();
for(int i =0;i<cookie.length;i++){
if(cookie[i].getName().equals("JSESSIONID")){
sessionID = cookie[i].getValue();
System.out.println("第一次:::::::::::"+sessionID);
}
}
File f1 = new File("code1.png");
get = new GetMethod( "http://shop.gkyc.cn/vcodeimg.jsp" );
h.executeMethod(get);
InputStream in = get.getResponseBodyAsStream();
FileOutputStream out = new FileOutputStream(f1);
byte[] b = new byte[1024];
int len = 0;
while((len=in.read(b))!= -1){
out.write(b,0,len);
}
cookie = h.getState().getCookies();
for(int i =0;i<cookie.length;i++){
if(cookie[i].getName().equals("JSESSIONID")){
sessionID = cookie[i].getValue();
System.out.println("第二次:::::::::::"+sessionID);
}
}
System.out.println("开始调用uu打码:"+
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
boolean status=UUAPI.checkAPI(); //校验API,必须调用一次,校验失败,打码不成功
if(!status){
System.out.print("API文件校验失败,无法使用打码服务");
return;
}
String veridCode=UUAPI.easyDecaptcha("code1.png", 8002)[1];
System.out.println("uu打码成功("+veridCode+"):"+
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
PostMethod post = new PostMethod("http://shop.gkyc.cn/login.jsp");
post.addParameter("userName", "wjszztrqyf");
post.addParameter("userPass", "wjszztrqyf");
post.addParameter("vcode", veridCode);
post.addParameter("loginBtn", "");
h.executeMethod(post);
cookie = h.getState().getCookies();
for(int i =0;i<cookie.length;i++){
if(cookie[i].getName().equals("JSESSIONID")){
sessionID = cookie[i].getValue();
System.out.println("第三次:::::::::::"+sessionID);
}
}
get = new GetMethod("http://shop.gkyc.cn/header.jsp");
/*if(sessionID!=null&&!sessionID.equals("")){
get.addRequestHeader("Cookie","JSESSIONID="+sessionID);
}*/
h.executeMethod(get);
cookie = h.getState().getCookies();
for(int i =0;i<cookie.length;i++){
if(cookie[i].getName().equals("JSESSIONID")){
sessionID = cookie[i].getValue();
System.out.println("第四次:::::::::::"+sessionID);
}
}
String response = get.getResponseBodyAsString();
//System.out.println(response);
if(response.contains("退出")){
System.out.println("OK");
}else{
System.out.println("false");
}
} catch (Exception e) {
e.printStackTrace();
}
}