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

📄 runnablethread.java

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

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 RunnableThread implements Runnable {
	static int count=0;
	  public void run() {
		 System.out.println(Thread.currentThread().getName());
		 try {
			Thread.currentThread().sleep(count);
			count++;
			System.out.println("count:"+count);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  check();
	  }
	  public static void main(String[] args) {
	    for(int i = 1; i <= 10000; i++)
	      new Thread(new RunnableThread(), "" + i).start();
	  }
	  void check(){
		  System.out.println("开始请求!");
//			 构造HttpClient的实例
			HttpClient httpClient = new HttpClient();
			String url = "http://192.168.3.18/download/normal/971449/C94DB6B687AD7C76EBE7A6FB8FB0E013/1.htm";
			PostMethod postMethod = new PostMethod(url);
			//		 填入各个表单域的值
			NameValuePair[] data = {new NameValuePair()};
//			 将表单的值放入postMethod中
			postMethod.setRequestBody(data);
			 

			
			
		/*	// 创建GET方法的实例
			GetMethod getMethod = new GetMethod("https://mybank.icbc.com.cn/icbc/perbank/index2.jsp");
			// 使用系统提供的默认的恢复策略
			getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
					new DefaultHttpMethodRetryHandler());*/
			try {
				// 执行postMethod
				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();
			}
		}
	}

⌨️ 快捷键说明

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