⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcon.java

📁 java实现httpclient功能 本工程实现了简单的网页游戏外挂功能
💻 JAVA
字号:
package com.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class TestCon extends TimerTask{
public static int a=0;
	
	public static void main(String[] args) {
		Timer timer=new Timer();
		timer.schedule(new TestCon(), 1000, 1000*60*5);
	}
	
	
	public String getUrlPage(String cookie){
		String getUrl="";
//		 构造HttpClient的实例
		HttpClient httpClient = new HttpClient();
		//首页
		String url = "http://gss3.51wan.com/main.php";

		PostMethod postMethod = new PostMethod(url);
		postMethod.addRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)");
		postMethod.addRequestHeader("Referer","http://gss3.51wan.com/main.php");
		postMethod.addRequestHeader("Connection","Keep-Alive");
		postMethod.addRequestHeader("Cookie",cookie);
		postMethod.addRequestHeader("Host","gss3.51wan.com");
		
//		 填入各个表单域的值
		NameValuePair[] data = {};
//		 将表单的值放入postMethod中
		postMethod.setRequestBody(data);
		try {
			// 执行getMethod
			int statusCode = httpClient.executeMethod(postMethod);
			if (statusCode != HttpStatus.SC_OK) {
				System.err.println("Method failed: "
						+ postMethod.getStatusLine());
			}
			// 读取内容
			InputStream is= postMethod.getResponseBodyAsStream();
			
			InputStreamReader isr=new InputStreamReader(is);
			
			BufferedReader in = new BufferedReader(isr);
			
			String inputLine;
			
			String str="";
			while ((inputLine = in.readLine()) != null) {
				if(inputLine.indexOf("个回合数")!=-1){
					str=inputLine.substring(inputLine.indexOf("task_over"));
					//System.out.println(str);
					str=str.substring(0,str.indexOf("'"));
					//System.out.println(str);
					break;
				}
			}
			getUrl="http://gss3.51wan.com/"+str;
			
		} catch (HttpException e) {
			// 发生致命的异常,可能是协议不对或者返回的内容有问题
			System.out.println("Please check your provided http address!");
			e.printStackTrace();
		} catch (IOException e) {
			// 发生网络异常
			e.printStackTrace();
		} finally {
			// 释放连接
			postMethod.releaseConnection();
			//System.out.println("获得url:"+getUrl);
			return getUrl;
		}
	}
	
	
	
	
	
	
	
	
	public void playPage(String taskurl,String cookie){
//		 构造HttpClient的实例
		HttpClient httpClient = new HttpClient();
		//首页
		//String url = "http://gss3.51wan.com/main.php";

		PostMethod postMethod = new PostMethod(taskurl);
		postMethod.addRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)");
		postMethod.addRequestHeader("Referer","http://gss3.51wan.com/main.php");
		postMethod.addRequestHeader("Connection","Keep-Alive");
		postMethod.addRequestHeader("Cookie",cookie);
		postMethod.addRequestHeader("Host","gss3.51wan.com");
		
//		 填入各个表单域的值
		NameValuePair[] data = {};
//		 将表单的值放入postMethod中
		postMethod.setRequestBody(data);
		try {
			// 执行getMethod
			int statusCode = httpClient.executeMethod(postMethod);
			if (statusCode != HttpStatus.SC_OK) {
				System.err.println("Method failed: "
						+ postMethod.getStatusLine());
			}
			// 读取内容
			InputStream is= postMethod.getResponseBodyAsStream();
			
			InputStreamReader isr=new InputStreamReader(is);
			
			BufferedReader in = new BufferedReader(isr);
			
			String inputLine;
			
			
			while ((inputLine = in.readLine()) != null) {
				//System.out.println(inputLine);
			}
			
			
		} catch (HttpException e) {
			// 发生致命的异常,可能是协议不对或者返回的内容有问题
			System.out.println("Please check your provided http address!");
			e.printStackTrace();
		} catch (IOException e) {
			// 发生网络异常
			e.printStackTrace();
		} finally {
			// 释放连接
			postMethod.releaseConnection();
		}
	}
	
	
	public  void tellYou(){
		try {
            String MyUrl = "http://www.163.com/";
            String[] cmd = {"cmd.exe", "/C", "start " + MyUrl};
 
            Process process = Runtime.getRuntime().exec(cmd);
            process.waitFor();
 
        } catch (Exception e) {
            System.out.println(e);
        }
	}

	public void checkHuiHe2(String cookie,String taskurl){
		if(getUrlPage(cookie).equals("http://gss3.51wan.com/")){
			playPage(taskurl,cookie);
		}
		
//		 构造HttpClient的实例
		HttpClient httpClient = new HttpClient();
		//首页
		String url = "http://gss3.51wan.com/main.php";

		PostMethod postMethod = new PostMethod(url);
		postMethod.addRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)");
		postMethod.addRequestHeader("Referer","http://gss3.51wan.com/main.php");
		postMethod.addRequestHeader("Connection","Keep-Alive");
		postMethod.addRequestHeader("Cookie",cookie);
		postMethod.addRequestHeader("Host","gss3.51wan.com");
		
//		 填入各个表单域的值
		NameValuePair[] data = {};
//		 将表单的值放入postMethod中
		postMethod.setRequestBody(data);
		try {
			// 执行getMethod
			int statusCode = httpClient.executeMethod(postMethod);
			if (statusCode != HttpStatus.SC_OK) {
				System.err.println("Method failed: "
						+ postMethod.getStatusLine());
			}
			// 读取内容
			InputStream is= postMethod.getResponseBodyAsStream();
			
			InputStreamReader isr=new InputStreamReader(is);
			
			BufferedReader in = new BufferedReader(isr);
			
			String inputLine;
			String str="";
			
			while ((inputLine = in.readLine()) != null) {
				if(inputLine.indexOf("回合数")!=-1){
					str=inputLine.substring(inputLine.indexOf("回合数")+4);
					str=str.substring(str.indexOf(">")+1,str.indexOf("/")).trim();
					//System.out.println(str);
					break;
				}
			}
			a=Integer.valueOf(str);
			//System.out.println("剩余回合数:"+a);
			if(a>=70){
				checkHuiHe1(cookie);
				String getUrl=getUrlPage(cookie);
				playPage(getUrl,cookie);
			}
			
		} catch (HttpException e) {
			// 发生致命的异常,可能是协议不对或者返回的内容有问题
			System.out.println("Please check your provided http address!");
			e.printStackTrace();
		} catch (IOException e) {
			// 发生网络异常
			e.printStackTrace();
		} finally {
			// 释放连接
			postMethod.releaseConnection();
		}
		
	}
	
	
	public void checkHuiHe1(String cookie){
//		 构造HttpClient的实例
		HttpClient httpClient = new HttpClient();
		//首页
		String url = "http://gss3.51wan.com/main.php";

		PostMethod postMethod = new PostMethod(url);
		postMethod.addRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)");
		postMethod.addRequestHeader("Referer","http://gss3.51wan.com/main.php");
		postMethod.addRequestHeader("Connection","Keep-Alive");
		postMethod.addRequestHeader("Cookie",cookie);
		postMethod.addRequestHeader("Host","gss3.51wan.com");
		
//		 填入各个表单域的值
		NameValuePair[] data = {};
//		 将表单的值放入postMethod中
		postMethod.setRequestBody(data);
		try {
			// 执行getMethod
			int statusCode = httpClient.executeMethod(postMethod);
			if (statusCode != HttpStatus.SC_OK) {
				System.err.println("Method failed: "
						+ postMethod.getStatusLine());
			}
			// 读取内容
			InputStream is= postMethod.getResponseBodyAsStream();
			
			InputStreamReader isr=new InputStreamReader(is);
			
			BufferedReader in = new BufferedReader(isr);
			
			String inputLine;
			
			
			while ((inputLine = in.readLine()) != null) {
				//System.out.println(inputLine);
			}
			
			
		} catch (HttpException e) {
			// 发生致命的异常,可能是协议不对或者返回的内容有问题
			System.out.println("Please check your provided http address!");
			e.printStackTrace();
		} catch (IOException e) {
			// 发生网络异常
			e.printStackTrace();
		} finally {
			// 释放连接
			postMethod.releaseConnection();
		}
		
	}
	
	
	public void play(String cookie,String taskurl){
		checkHuiHe1(cookie);
		while(true){
			checkHuiHe1(cookie);
			checkHuiHe2(cookie, taskurl);
			if(a<70){
				break;
			}
		}
		
	}
	

	public void run() {
		String taskurl = "http://gss3.51wan.com/task_take.php?task_id=20";
		String cookie="sk=6uqf6mkklr9ti6hjlkn842auj0; uid=14849877; uname=77861515; money=0; point=100; co=0; usertitle=%B0%D7%C3%E6%CD%E8%D7%D3; pk=67d45a839b96b61d; mp=75c9781a9f9130666462f4da26258990; mp1=75c9781a9f9130666462f4da26258990; PHPSESSID=392kjmsdnm571neklkq5r79ng4";
		play(cookie,taskurl);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -