main.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 |
import javax.net.ssl.HttpsURLConnection; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Oxford { public static void main(String[] args) { final String language = "en-gb"; final String word = "Ace"; final String fields = "pronunciations"; final String strictMatch = "false"; final String word_id = word.toLowerCase(); final String restUrl = "https://od-api.oxforddictionaries.com:443/api/v2/entries/" + language + "/" + word_id + "?" + "fields=" + fields + "&strictMatch=" + strictMatch; //TODO: replace with your own app id and app key final String app_id = ""; final String app_key = ""; try { URL url = new URL(restUrl); HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); urlConnection.setRequestProperty("Accept", "application/json"); urlConnection.setRequestProperty("app_id", app_id); urlConnection.setRequestProperty("app_key", app_key); // read the output from the server BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); StringBuilder stringBuilder = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { stringBuilder.append(line + "\n"); } System.out.println(stringBuilder.toString()); } catch (IOException e) { e.printStackTrace(); } } } |