Skip to content

Instantly share code, notes, and snippets.

@charleyhine
Last active September 30, 2015 23:54
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 charleyhine/09225390f5460d4e86b5 to your computer and use it in GitHub Desktop.
Save charleyhine/09225390f5460d4e86b5 to your computer and use it in GitHub Desktop.
Simple GET with countdown
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
private String getResponse(URL url){
try {
HttpURLConnection c = url.openConnection();
c.setReadTimeout(1000); // 1 second
br = new BufferedReader(new InputStreamReader(c.getInputStream()));
String line;
StringBuilder sb = new StringBuilder();
while ((line = br.readLine()) != null) {
sb.append(line);
}
JSONObject json = new JSONObject(sb.toString());
} catch (Exception e) {
// do what we do today
// return false; ?
}
if (c.getResponseCode() == 200) {
return json.getString("authorized");
} else {
// return false; ?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment