1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

簡単なJavaで Watson Weather Company Data から天気予報を取得する

Posted at

	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();

	}


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?