Created
June 27, 2016 10:21
-
-
Save kkashyap1707/1dd4c032e226c17fe0d6b3ef10ccb89a 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
public String apiMethod_GET() | |
{ | |
String foutput = ""; | |
try | |
{ | |
URL url = new URL(uri); | |
System.out.println("API URL : " + url); | |
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |
conn.setDoOutput(true); | |
conn.setRequestMethod("GET"); | |
conn.setRequestProperty("Content-Type", "application/json"); | |
if(authToken!=null && authToken.length()>0) | |
{ | |
conn.setRequestProperty("X-Auth-Token",authToken); | |
} | |
int Responsecode = conn.getResponseCode(); | |
String ResponseCode=String.valueOf(Responsecode); | |
String ResponseMessage = conn.getResponseMessage(); | |
String LoginContentType = conn.getContentType(); | |
if (conn.getResponseCode() != 200) | |
{ | |
throw new RuntimeException("Failed : HTTP Error code : " + conn.getResponseCode()); | |
} | |
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); | |
String output ; | |
while ((output = br.readLine()) != null) | |
{ | |
foutput = foutput + output; | |
} | |
} | |
catch (MalformedURLException e) | |
{ | |
e.printStackTrace(); | |
} | |
catch (IOException e) | |
{ | |
e.printStackTrace(); | |
} | |
return foutput; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment