Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created December 28, 2017 09:25
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 jezinka/7b6158e7320136686f5b0ad59c19eac2 to your computer and use it in GitHub Desktop.
Save jezinka/7b6158e7320136686f5b0ad59c19eac2 to your computer and use it in GitHub Desktop.
private String makeOdjazdQuery(URL url) {
if (url != null) {
try {
return getResponseFromHttpUrl(url);
} catch (IOException e) {
e.printStackTrace();
}
}
return "";
}
private static String getResponseFromHttpUrl(URL url) throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = urlConnection.getInputStream();
Scanner scanner = new Scanner(in);
scanner.useDelimiter("\\A");
boolean hasInput = scanner.hasNext();
if (hasInput) {
return scanner.next();
} else {
return null;
}
} finally {
urlConnection.disconnect();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment