RestUtil.java
1.26 KB
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
package com.bjivt.util;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class RestUtil {
public String load(String url,String secret, String query) throws Exception {
URL restURL = new URL(url);
HttpURLConnection conn = (HttpURLConnection) restURL.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setAllowUserInteraction(false);
conn.addRequestProperty("Authorization", secret);
PrintStream ps = new PrintStream(conn.getOutputStream());
ps.print(query);
ps.close();
BufferedReader bReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line,resultStr="";
while(null != (line=bReader.readLine())) {
resultStr +=line;
}
bReader.close();
return resultStr;
}
public static void main(String []args) {
try {
RestUtil restUtil = new RestUtil();
String resultString = restUtil.load("http://192.168.4.46:9090/plugins/restapi/v1/messages/sendgroup?from=100006&roomname=1000061467024610857","75gPAEXkNl8homHD", "中文是否正常");
System.out.println(resultString);
} catch (Exception e) {
// TODO: handle exception
System.out.print(e.getMessage());
}
}
}