Last active
June 10, 2018 16:37
-
-
Save edpichler/79ca8bd1da02aab28d2470e16f95c328 to your computer and use it in GitHub Desktop.
Get All airports with IATA codes retrieving EasyPNR Web service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
public class EasyPNRExample { | |
/** | |
* https://www.easypnr.com/webservice | |
* @param args | |
* @throws Exception | |
*/ | |
public static void main(String[] args) throws Exception { | |
URL url = new URL("https://api.easypnr.com/v4/airports"); | |
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |
conn.setRequestMethod("GET"); | |
conn.setRequestProperty("Accept", "application/json"); | |
conn.setRequestProperty("X-Api-Key", "yourkey"); //get your own key in www.easypnr.com | |
if (conn.getResponseCode() != 200) { | |
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); | |
} | |
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); | |
String apiOutput = br.readLine(); | |
System.out.println(apiOutput); | |
conn.disconnect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment