blob: 07eab452a7ce59224d883af493fd1df88d5d3cfe [file] [log] [blame]
pingping-lina2cbfad2013-03-07 08:39:21 +08001package net.floodlightcontroller.restclient;
2
3import java.io.IOException;
4import java.net.HttpURLConnection;
5import java.net.MalformedURLException;
6import java.net.URL;
7
8public 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}