Android Basiccookiestore, Cookies And Httpget
I have a an app that should send a GET request to a URL and send some cookies along with it. I've been looking at a few code examples for BasicCookieStore and Cookie classes, but I
Solution 1:
To use cookies you need something along the lines of:
CookieStorecookieStore=newBasicCookieStore();
DefaultHttpClienthttpclient=newDefaultHttpClient();
HttpContextctx=newBasicHttpContext();
ctx.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGetget=newHttpGet("your URL here");
HttpResponseresponse= httpclient.execute(get,ctx);
And if you want to keep cookies between requests, you have to reuse cookieStore
and ctx
for every request.
Also, you may read your cookieStore
to see what's inside:
List<Cookie> cookies = cookieStore.getCookies();
if( !cookies.isEmpty() ){
for (Cookie cookie : cookies){
StringcookieString= cookie.getName() + " : " + cookie.getValue();
Log.info(TAG, cookieString);
}
}
Post a Comment for "Android Basiccookiestore, Cookies And Httpget"