Skip to content

Instantly share code, notes, and snippets.

@itayher
Last active May 6, 2016 14:51
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 itayher/cd05e8af6583956b80c036be7b3d3c81 to your computer and use it in GitHub Desktop.
Save itayher/cd05e8af6583956b80c036be7b3d3c81 to your computer and use it in GitHub Desktop.

Use this code snippet of Android in order to access Back&, make a GET call that returns string which you can transform into JSON:

StringBuilder stringBuilder = new StringBuilder();
try {
    String authorization = "<< AnonymousToken >>";

    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setRequestMethod("GET");
    conn.setRequestProperty("AnonymousToken", authorization);
    conn.setRequestProperty("Content-Type", "application/json");

    conn.connect();

    int responseCode = conn.getResponseCode();

    if (responseCode == HttpsURLConnection.HTTP_OK) {
        String line;
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    } else {
        Log.d(TAG, "readRemoteJson", conn.getResponseMessage(), false);
        return "";
    }
} catch (Exception e) {
    Log.e(TAG, "readRemoteJson", e.getMessage(), true);
}
return  stringBuilder.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment