增加微信通知POST请求工具类

master
Yangwl 9 months ago
parent 0e5f5907e1
commit 87f3ecab69

@ -5,10 +5,7 @@ import org.slf4j.LoggerFactory;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.io.*; import java.io.*;
import java.net.ConnectException; import java.net.*;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
/** /**
@ -120,6 +117,30 @@ public class HttpUtils {
return result.toString(); 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 * URL POST
* *

Loading…
Cancel
Save