簡単なJavaで Watson Weather Company Data から天気予報を取得する
4235 ワード
public static void main(String[] args) throws Exception {
String username = "xxx";
String password = "xxx";
URL url = new URL(
"https://twcservice.mybluemix.net/api/weather/v1/geocode/35.681167/139.76705/forecast/daily/3day.json?language=ja-JP");
URLConnection conn = url.openConnection();
conn.setRequestProperty(
"Authorization",
"Basic "
+ Base64.getEncoder().encodeToString(
(username + ":" + password).getBytes()));
Base64.getEncoder().encodeToString("username:password".getBytes()));
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println(sb.toString());
br.close();
}
Author And Source
この問題について(簡単なJavaで Watson Weather Company Data から天気予報を取得する), 我々は、より多くの情報をここで見つけました https://qiita.com/oyahiroki/items/2d2c0dccfc1557a9dc38著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .