pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame^] | 1 | package net.floodlightcontroller.restclient; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.net.HttpURLConnection; |
| 5 | import java.net.MalformedURLException; |
| 6 | import java.net.URL; |
| 7 | |
| 8 | public class RestClient { |
| 9 | |
| 10 | public static void get (String str) { |
| 11 | |
| 12 | if (str == null) |
| 13 | return; |
| 14 | |
| 15 | try { |
| 16 | |
| 17 | URL url = new URL(str); |
| 18 | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| 19 | conn.setRequestMethod("GET"); |
| 20 | conn.setRequestProperty("Accept", "application/json"); |
| 21 | |
| 22 | if (conn.getResponseCode() != 200) { |
| 23 | throw new RuntimeException("Failed : HTTP error code : " |
| 24 | + conn.getResponseCode()); |
| 25 | } |
| 26 | |
| 27 | /* Disable reading the output from the server for now |
| 28 | * |
| 29 | BufferedReader br = new BufferedReader(new InputStreamReader( |
| 30 | (conn.getInputStream()))); |
| 31 | |
| 32 | String output; |
| 33 | System.out.println("Output from Server .... \n"); |
| 34 | while ((output = br.readLine()) != null) { |
| 35 | System.out.println(output); |
| 36 | } |
| 37 | */ |
| 38 | |
| 39 | conn.disconnect(); |
| 40 | |
| 41 | } catch (MalformedURLException e) { |
| 42 | |
| 43 | e.printStackTrace(); |
| 44 | |
| 45 | } catch (IOException e) { |
| 46 | |
| 47 | e.printStackTrace(); |
| 48 | |
| 49 | } |
| 50 | } |
| 51 | } |