Skip to content

Instantly share code, notes, and snippets.

@kkashyap1707
Created June 27, 2016 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkashyap1707/1dd4c032e226c17fe0d6b3ef10ccb89a to your computer and use it in GitHub Desktop.
Save kkashyap1707/1dd4c032e226c17fe0d6b3ef10ccb89a to your computer and use it in GitHub Desktop.
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