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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With