Skip to content

Instantly share code, notes, and snippets.

@sheharyarn
Last active August 29, 2015 14:10
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 sheharyarn/950561cd3d4487f69e46 to your computer and use it in GitHub Desktop.
Save sheharyarn/950561cd3d4487f69e46 to your computer and use it in GitHub Desktop.
Using AndroidAsyncHttp Library
RequestParams params = new RequestParams();
params.put("email", "a@b.c");
params.put("password", "12345678");
APIClient.post("/login", params, new JsonHttpResponseHandler() {
// @Override them all
public void onStart() { } // Runs before anything else
public void onFinish() { } // Runs after everything else
// If don't know your response type
public void onSuccess(int statusCode, Header[] headers, byte[] response) { }
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) { }
// If your responses are simple text
public void onSuccess(int statusCode, Header[] headers, String response) { }
public void onFailure(int statusCode, Header[] headers, String error, Throwable throwable) { }
// If your responses are JSON Objects (or Arrays)
public void onSuccess(int statusCode, Header[] headers, JSONObject response) { }
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject error) { }
public void onSuccess(int statusCode, Header[] headers, JSONArray response) { }
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errors) { }
// Fuck me, right?
// You can use more than one at a time
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment