-
Notifications
You must be signed in to change notification settings - Fork 44
/
Http.java
127 lines (116 loc) · 5.19 KB
/
Http.java
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
package com.webRequest;
import com.github.kevinsawicki.http.HttpRequest;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class Http {
public static ArrayList Response (String str,String cookie, String ua,String xHeaders,String methods,String dataBody,String enctypeBody,boolean follow){
ArrayList responseList = new ArrayList();
int code,contentLength;
String body,banner;
HttpRequest response = null;
Map<String, String> headers = new HashMap<String, String>();
if (ua.equals("")){
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" +
" (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36";
}
if (!"SESSION=A202106084F2...".equals(cookie)){
headers.put("cookie",cookie);
}
headers.put("User-Agent",ua);
if (!xHeaders.equals("X-Forwarded-for: 127.0.0.1\nReferer: ...") && !xHeaders.equals("")) {
System.out.println(xHeaders);
try {
String[] split1 = xHeaders.split("\n");
for (String s : split1) {
String[] split2 = s.split(": ");
headers.put(split2[0], split2[1]);
}
}catch (Exception e){
e.printStackTrace();
}
}
if (methods == "post")
{ headers.put("Content-type",enctypeBody);
response = HttpRequest.post(str).headers(headers).trustAllHosts().trustAllCerts().send(dataBody).followRedirects(follow);
}
if (methods == "head"){
response = HttpRequest.head(str).headers(headers).trustAllCerts().trustAllHosts().followRedirects(follow);
}
if(methods == "get"){
response = HttpRequest.get(str).headers(headers).trustAllHosts().trustAllCerts().followRedirects(follow);
}
code = response.code();
body = response.body();
banner = response.header("server");
contentLength = response.contentLength();
if (contentLength == -1) {
try {
contentLength = body.getBytes("UTF-8").length;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
responseList.add(code);
responseList.add(body);
responseList.add(banner);
responseList.add(contentLength);
return responseList;
}
// 重载方法
public static ArrayList Response (String str,String cookie, String ua,String xHeaders,String methods,String dataBody,String enctypeBody,boolean follow,String host,int port){
ArrayList responseList = new ArrayList();
int code,contentLength;
String body,banner;
Map<String, String> headers = new HashMap<String, String>();
HttpRequest response = null;
if (ua.equals("")){
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" +
" (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36";
}
// System.out.println(!"SESSION=A202106084F2...".equals(cookie));
if (!"SESSION=A202106084F2...".equals(cookie)){
headers.put("cookie",cookie);
}
headers.put("User-Agent",ua);
if (!xHeaders.equals("X-Forwarded-for: 127.0.0.1\nReferer: ...") && !xHeaders.equals("")){
System.out.println(xHeaders);
try {
String[] split1 = xHeaders.split("\n");
for (String s : split1) {
String[] split2 = s.split(": ");
headers.put(split2[0], split2[1]);
}
}catch (Exception e){
e.printStackTrace();
}
}
if (methods == "post")
{ headers.put("Content-type",enctypeBody);
response = HttpRequest.post(str).useProxy(host, port).headers(headers).trustAllHosts().trustAllCerts().send(dataBody).followRedirects(follow);
}
if (methods == "head"){
response = HttpRequest.head(str).useProxy(host, port).headers(headers).trustAllCerts().trustAllHosts().followRedirects(follow);
}
if(methods == "get"){
response = HttpRequest.get(str).useProxy(host, port).headers(headers).trustAllHosts().trustAllCerts().followRedirects(follow);
}
code = response.code();
body = response.body();
banner = response.header("server");
contentLength = response.contentLength();
if (contentLength == -1) {
try {
contentLength = body.getBytes("UTF-8").length;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
responseList.add(code);
responseList.add(body);
responseList.add(banner);
responseList.add(contentLength);
return responseList;
}
}