tyreworldonline DVLA REG Quick Lookup

/* ==========[ API Usage Example - Java ]==========

Steps: 1. Use any recent JDK e.g. v7, v8

2. Construct a URL Object

3. Open a connection using the URL

4. Set the request method i.e. GET

5. Invoke connection and examine the HTTP response code

6. Construct a BufferedReader and loop through the response stream

7. Deserialize the outpu

t to standard output ==============================================

*/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class JavaClient { public static void main(String... args) { try { String ApiKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; String VRM = "KM14AKK"; String DataPackage = "VehicleData"; String QueryStringOptionals = "&api_nullitems=1"; int ApiVersion = 2; URL url = new URL( "https://uk1.ukvehicledata.co.uk/api/datapackage/" + DataPackage + "?v=" + ApiVersion + QueryStringOptionals + "&key_vrm=" + VRM + "&auth_apikey=" + ApiKey ); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }