新增NicePT签到

新增https工具
This commit is contained in:
2022-02-08 12:27:07 +08:00
parent 7cb003544b
commit b4484f1424
4 changed files with 111 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ package com.yutou.qqbot.utlis;
import com.alibaba.fastjson.JSONObject;
import com.yutou.qqbot.interfaces.DownloadInterface;
import org.jetbrains.annotations.NotNull;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
@@ -14,7 +15,7 @@ public class HttpTools {
private static final int HttpRequestIndex = 3;
public static String get(String url) {
return https_get(url, null);
return http_get(url,null);
}
public static String post(final String url, final byte[] body) {
@@ -27,29 +28,45 @@ public class HttpTools {
public static String https_get(String url, Map<String, String> header) {
try {
URLConnection connection;
connection = new URL(url).openConnection();
connection.setRequestProperty("User-Agent", getExtUa());
if (header != null) {
for (String key : header.keySet()) {
connection.addRequestProperty(key, header.get(key));
}
}
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder str = new StringBuilder();
String tmp;
while ((tmp = reader.readLine()) != null) {
str.append(tmp);
}
reader.close();
return str.toString();
HttpsURLConnection connection;
connection = (HttpsURLConnection) new URL(url).openConnection();
return urlConnection(header, connection);
} catch (Exception e) {
System.err.println("error url = " + url);
e.printStackTrace();
}
return null;
}
public static String http_get(String url,Map<String,String> header){
try {
HttpURLConnection connection;
connection = (HttpURLConnection) new URL(url).openConnection();
return urlConnection(header, connection);
} catch (Exception e) {
System.err.println("error url = " + url);
e.printStackTrace();
}
return null;
}
@NotNull
private static String urlConnection(Map<String, String> header, HttpURLConnection connection) throws IOException {
connection.setRequestProperty("User-Agent", getExtUa());
if (header != null) {
for (String key : header.keySet()) {
connection.addRequestProperty(key, header.get(key));
}
}
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder str = new StringBuilder();
String tmp;
while ((tmp = reader.readLine()) != null) {
str.append(tmp);
}
reader.close();
return str.toString();
}
public static String http_post(String url, byte[] body, int index, Map<String, String> headers) {
String tmp;

View File

@@ -62,8 +62,8 @@ public class WebClient {
ChromeOptions options = new ChromeOptions();
// options.addArguments("--disable-gpu");
// options.addArguments("blink-settings=imagesEnabled=false");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
// options.addArguments("--headless");
// options.addArguments("--no-sandbox");
// options.addArguments("--incognito");
options.addArguments("--disable-plugins");
options.addArguments("--lang=zh-CN");