-
Notifications
You must be signed in to change notification settings - Fork 5
/
Example.java
46 lines (36 loc) · 1.46 KB
/
Example.java
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
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
public class Example {
public static void main(String[] args) throws Exception {
String publicKey = "XXX";
String secretKey = "XXX";
SeniverseUtils seniverseUtils = new SeniverseUtils();
seniverseUtils.addParameter("ts", new Date().getTime() / 1000);
seniverseUtils.addParameter("fields", "precip_minutely");
seniverseUtils.addParameter("public_key", publicKey);
seniverseUtils.addParameter("locations", "29.5617:120.0962");
try {
String urlStr = seniverseUtils.getUrl("https://api.seniverse.com/v4", secretKey);
URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
InputStream stream = conn.getInputStream();
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = stream.read(buffer)) != -1) {
outSteam.write(buffer, 0, len);
}
outSteam.close();
stream.close();
String result = outSteam.toString();
System.out.println("");
System.out.println("url: ".concat(urlStr));
System.out.println(result);
} catch (Error error) {
System.err.println(error.getMessage());
}
}
}