5

Regarding to LoopJ AndroidAsyncHttp examples I make a get request like this:

    final TextView text = (TextView) findViewById(R.id.textView);
    AsyncHttpClient client = new AsyncHttpClient();
    client.get("http://example.com/mypage/", new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(String response) {
            text.append(response);
        }
    });

I also add cookies:

    PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
    client.setCookieStore(myCookieStore);
    BasicClientCookie newCookie = new BasicClientCookie("id", 17882);
    myCookieStore.addCookie(newCookie);

But while making a GET request how can I send my cookies inside the request object ?

Regarding to documentation client has these method signatures:

 void   get(Context context, String url, AsyncHttpResponseHandler responseHandler) 
 void   get(Context context, String url, Header[] headers, RequestParams params, AsyncHttpResponseHandler responseHandler) 
 void   get(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) 
 void   get(String url, AsyncHttpResponseHandler responseHandler) 
 void   get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) 

I would be happy if you can give an example that sends persistent cookies inside the GET request.

Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
trante
  • 33,518
  • 47
  • 192
  • 272
  • 1
    you are adding cookies already when you set client.setCookieStore(myCookieStore). Just make sure you add them before client.get() – robotoaster Aug 01 '13 at 07:33

1 Answers1

3

Since you are creating your own PersistentCookieStore instance, Simply use the myCookieStore instance you created. Like @robotoaster says add it before get().

OR

Do this

HttpContext httpContext = httpClient.getHttpContext();
CookieStore cookieStore = (CookieStore) httpContext.getAttribute(ClientContext.COOKIE_STORE);

Then follow instructions at http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/CookieStore.html .

Source: Cookies in loopj for android (Straight from loopj)

Community
  • 1
  • 1
Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103