AsyncHttpClient asynClient = new AsyncHttpClient(); void post(Context context,String url, StringEntity entity,String string, AsyncHttpResponseHandler asyncHttpResponseHandler) { asynClient.addHeader("Accept", "application/json"); asynClient.addHeader("Content-type", "application/json"); asynClient.post(context, url, entity, "application/json", asyncHttpResponseHandler ); }
public static void getCards(Context context, CardsResponse cardsResponse) { AsyncHttpClient client = new AsyncHttpClient(); client.addHeader("x-access-token", Preferences.getToken(context)); client.get("http://api.app.com/users/" + Preferences.getID(context), null, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] bytes) { Log.d("debugIID", "Cards success : " + statusCode); String json = new String(bytes); try { jsonObj = new JSONObject(json); cardsResponse.onResponseReceived(jsonResponse); // This line will return to your caller } catch (JSONException e) { e.printStackTrace(); } Log.d("debug", "Cards JSONObject : " + jsonObj); } @Override public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable throwable) { Log.d("debug", "Cards failure : " + statusCode); } }); }
responce); Log.e("", "token_type " + jsonObject.getString("token_type") + " access_token " + jsonObject.getString("access_token")); client.addHeader("Authorization", jsonObject.getString("token_type") + " " + jsonObject.getString("access_token")); client.get(url, asyncHttpResponseHandler); } catch (JSONException e) {
myCookieStore = new PersistentCookieStore(context); client.setCookieStore(myCookieStore); client.addHeader("Content-type", "application/json");