Get weather forecasts from Watson Weather Company Data in simple Java


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

	}


Recommended Posts

Get weather forecasts from Watson Weather Company Data in simple Java
Get weather forecasts from Watson Weather Company Data with a simple JSP
[Java] Get data from DB using singleton service in Spring (Boot)
Get history from Zabbix server in Java
Get weather forecast from OpenWeatherMap in Rails
How to get Class from Element in Java
Get unixtime (seconds) from ZonedDateTime in Scala / Java
[Java] Get KFunction from Method / Constructor in Java [Kotlin]
Simple htmlspecialchars in Java
Get EXIF information in Java
Importing Excel data in Java 2
[Java] Get KClass in Java [Kotlin]
Import Excel data in Java
Easily get an integer from a system property in Java
2 Implement simple parsing in Java
Get attributes and values from an XML file in Java
Importing Excel data in Java 3
CData Software Hands-on (Get Twitter data from Java console application)
Get a non-empty collection from an Optional stream in java
How to get and add data from Firebase Firestore in Ruby
3 Implement a simple interpreter in Java
Display Firestore data in RecyclerView [Java]
Get country from IP address (Java)
Get Null-safe Map values in Java
A simple sample callback in Java
Get GTFS data from OpenTripPlanner Graph
Get stuck in a Java primer
1 Implement simple lexical analysis in Java
Try to get data from database using MyBatis in Micronaut + Kotlin project
Study Deep Learning from scratch in Java.
Get the result of POST in Java
How to get date data in Ruby
Create variable length binary data in Java
Data processing using stream API from Java 8
Use PostgreSQL data type (jsonb) from Java
Call Java method from JavaScript executed in Java
OCR in Java (character recognition from images)
Get caller information from stack trace (java)
Reverse Key from Value in Java Map
[IOS] How to get data from DynamoDB
Using JavaScript from Java in Rhino 2021 version
Kinesis Data Streams from zero Java experience (1)
[Java] Get tag information from music files
How to get the date in java
Kinesis Data Streams from zero Java experience (3.1)
Call Visual Recognition in Watson Java SDK
Kinesis Data Streams from zero Java experience (3.2)