Last active
September 30, 2015 23:54
-
-
Save charleyhine/09225390f5460d4e86b5 to your computer and use it in GitHub Desktop.
Simple GET with countdown
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
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