|
|
|
@ -5,10 +5,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.*;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.ConnectException;
|
|
|
|
|
import java.net.SocketTimeoutException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.net.URLConnection;
|
|
|
|
|
import java.net.*;
|
|
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -120,6 +117,30 @@ public class HttpUtils {
|
|
|
|
|
return result.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String sendPostWechart(String requestUrl, String jsonInputString) throws Exception {
|
|
|
|
|
URL url = new URL(requestUrl);
|
|
|
|
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
|
|
|
|
con.setRequestMethod("POST");
|
|
|
|
|
con.setRequestProperty("Content-Type", "application/json; utf-8");
|
|
|
|
|
con.setRequestProperty("Accept", "application/json");
|
|
|
|
|
con.setDoOutput(true);
|
|
|
|
|
|
|
|
|
|
try (OutputStream os = con.getOutputStream()) {
|
|
|
|
|
byte[] input = jsonInputString.getBytes("utf-8");
|
|
|
|
|
os.write(input, 0, input.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle the response (optional)
|
|
|
|
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))) {
|
|
|
|
|
StringBuilder response = new StringBuilder();
|
|
|
|
|
String responseLine;
|
|
|
|
|
while ((responseLine = br.readLine()) != null) {
|
|
|
|
|
response.append(responseLine.trim());
|
|
|
|
|
}
|
|
|
|
|
return response.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 向指定 URL 发送POST方法的请求
|
|
|
|
|
*
|
|
|
|
|