Last active
December 17, 2015 10:45
-
-
Save ekirastogi/00e7fabcc4cfa3277dcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ekiras.test; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.net.URLConnection; | |
public class TestApi { | |
private static String apiUrl = "https://localhost:8080/v1/home"; | |
public static void main(String args[]){ | |
test(); | |
} | |
public static void test(){ | |
try { | |
URL url = new URL(apiUrl); | |
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | |
connection.setRequestMethod("GET"); | |
connection.setRequestProperty("Accept-Encoding", "gzip"); | |
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |
String line = ""; | |
while((line=reader.readLine())!=null){ | |
System.out.println(">> "+ line); | |
} | |
System.out.println(connection.getContent().toString()); | |
} catch (MalformedURLException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment