| 10 | public class Http { |
| 11 | |
| 12 | public static ArrayList Response (String str,String cookie, String ua,String xHeaders,String methods,String dataBody,String enctypeBody,boolean follow){ |
| 13 | ArrayList responseList = new ArrayList(); |
| 14 | int code,contentLength; |
| 15 | String body,banner; |
| 16 | HttpRequest response = null; |
| 17 | Map<String, String> headers = new HashMap<String, String>(); |
| 18 | if (ua.equals("")){ |
| 19 | ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" + |
| 20 | " (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"; |
| 21 | } |
| 22 | if (!"SESSION=A202106084F2...".equals(cookie)){ |
| 23 | headers.put("cookie",cookie); |
| 24 | } |
| 25 | |
| 26 | |
| 27 | |
| 28 | headers.put("User-Agent",ua); |
| 29 | if (!xHeaders.equals("X-Forwarded-for: 127.0.0.1\nReferer: ...") && !xHeaders.equals("")) { |
| 30 | System.out.println(xHeaders); |
| 31 | try { |
| 32 | String[] split1 = xHeaders.split("\n"); |
| 33 | for (String s : split1) { |
| 34 | String[] split2 = s.split(": "); |
| 35 | headers.put(split2[0], split2[1]); |
| 36 | } |
| 37 | }catch (Exception e){ |
| 38 | e.printStackTrace(); |
| 39 | } |
| 40 | } |
| 41 | //if else 为处理https和http请求 |
| 42 | if (str.indexOf("https")!=-1) { |
| 43 | if (methods == "post") { |
| 44 | headers.put("Content-type", enctypeBody); |
| 45 | response = HttpRequest.post(str).headers(headers).trustAllHosts().trustAllCerts().send(dataBody).followRedirects(follow).connectTimeout(5000).readTimeout(10000); |
| 46 | //Accept all certificates |
| 47 | response.trustAllCerts(); |
| 48 | //Accept all hostnames |
| 49 | response.trustAllHosts(); |
| 50 | |
| 51 | } |
| 52 | if (methods == "head") { |
| 53 | response = HttpRequest.head(str).headers(headers).trustAllCerts().trustAllHosts().followRedirects(follow).connectTimeout(5000).readTimeout(10000); |
| 54 | //Accept all certificates |
| 55 | response.trustAllCerts(); |
| 56 | //Accept all hostnames |
| 57 | response.trustAllHosts(); |
| 58 | } |
| 59 | if (methods == "get") { |
| 60 | response = HttpRequest.get(str).headers(headers).trustAllHosts().trustAllCerts().followRedirects(follow).connectTimeout(5000).readTimeout(10000); |
| 61 | //Accept all certificates |
| 62 | response.trustAllCerts(); |
| 63 | //Accept all hostnames |
| 64 | response.trustAllHosts(); |
| 65 | } |
| 66 | } |
| 67 | else{ |
| 68 | if (methods == "post") { |
| 69 | headers.put("Content-type", enctypeBody); |