Advertisement
Guest User

API_Example

a guest
Dec 18th, 2018
1,480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. try {        // Create a URL and open a connection
  2.             String url = "https://api.fortnitetracker.com/v1/profile/psn/GOPJ1";
  3.             URL FortniteURL = new URL(url);
  4.             HttpURLConnection urlConnection =
  5.                     (HttpURLConnection) FortniteURL.openConnection();
  6.  
  7.             // Set the paramters for the HTTP Request
  8.             urlConnection.setRequestMethod("GET");
  9.             urlConnection.setConnectTimeout(10000);
  10.             urlConnection.setReadTimeout(10000);
  11.             urlConnection.setRequestProperty("TRN-Api-Key", "MY KEY HERE");
  12.  
  13.             // Create an input stream and wrap in a BufferedReader to read the
  14.             // response.
  15.             BufferedReader in =
  16.                     new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
  17.             String inputLine;
  18.             StringBuilder response = new StringBuilder();
  19.  
  20.             while ((inputLine = in.readLine()) != null) {
  21.                 response.append(inputLine);
  22.             }
  23.  
  24.             // MAKE SURE TO CLOSE YOUR CONNECTION!
  25.             in.close();
  26.  
  27.             // response is the contents of the XML
  28.             System.out.println(response);
  29.             System.out.println();
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement