Skip to content

Cookies do not appear to be being sent #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
amdprophet opened this issue May 23, 2011 · 5 comments
Closed

Cookies do not appear to be being sent #1

amdprophet opened this issue May 23, 2011 · 5 comments

Comments

@amdprophet
Copy link

I created a BasicClientCookie, added it to a PersistentCookieStore, followed by setting the CookieStore in the AsyncHttpClient but the Cookie field does not appear to be set in the request. I'm not sure if I'm missing something.

@amdprophet
Copy link
Author

It turns out I wasn't actually adding the PersistentCookieStore to the AsyncHttpClient. Sorry about that!

@loopj
Copy link
Collaborator

loopj commented May 29, 2011

Make sure you are setting the version/domain/path on the BasicClientCookie you are creating. For example:

BasicClientCookie newCookie = new BasicClientCookie("cookiesare", "awesome");
newCookie.setVersion(1);
newCookie.setDomain("my.domain.com");
newCookie.setPath("/");
cookies.addCookie(newCookie);

If you add a cookie like this to the PersistentCookieStore then it will get sent along with requests to my.domain.com

@dbzhang
Copy link

dbzhang commented Dec 28, 2011

Nevermind, I found my mistake. My cookies were being overwritten when i went from http to https. Great job with the asyncClient, it works great.


I'm having trouble using stored cookies with a request.

I used the following lines to instantiate the AsyncHttpClient and automatically add cookies from my server:
' AsyncClient = new AsyncHttpClient();
PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
AsyncClient.setCookieStore(myCookieStore); '

I use the following line to make requests: AsyncClient.get(urlStr, new AsyncHttpResponseHandler();

I made requestA to fetch & store session cookies in myCookieStore. When I make requestB it seems like the stored cookies are not sent along with my request. Am I missing any steps here? Thanks for your help.

pinhao pushed a commit to pinhao/android-async-http that referenced this issue Feb 26, 2013
…0d860eee6fa67ef00958da0eae1aef01

Recent changes at original repo working with refactored response handlers
smarek pushed a commit that referenced this issue May 9, 2015
合并原作者的更新
@griffins
Copy link

griffins commented Jun 6, 2015

hello guys. am abit late but i need your help.
Cookies are not sent to the server. dont know why.
here is my code

private void init() {
        PersistentCookieStore myCookies = new PersistentCookieStore(mContext);
        if (mContext == null) {
            Log.d("WebClient", "Warning Context is null. Cookies wont work");
        }

        List<Cookie> cookies = myCookies.getCookies();
        Log.d("WebClient", "Cookies " + cookies.size());
        for (Cookie c : cookies) {
            String cookieName = "";
            String cookieValue = "";
            cookieName = c.getName().toString();
            cookieValue = c.getValue().toString();
            Log.d("WebClient", "Cookie Name:" + cookieName + " Cookie Value: " + cookieValue);
        }
        client.setCookieStore(myCookies);
    }

and here is my logcat

06-06 16:57:57.047  28383-28383/com.spartan D/WebClient﹕ Cookies 0
06-06 16:57:57.048  28383-28383/com.spartan V/WebClient﹕ Sending HTTP POST http://192.168.43.102/fcmapi2/auth
06-06 16:57:57.216  28383-28383/com.spartan D/WebClient﹕ {
    "data": {
    "user_id": "9",
    "username": "test",
    "name": "Griffins Oringo",
    "email": "test@spartanafrica.com",
    "u_id": "A09"
    },
    "code": 200
    }
06-06 16:57:57.224  28383-28383/com.spartan D/WebClient﹕ Cookies 0
06-06 16:57:57.226  28383-28383/com.spartan V/WebClient﹕ Sending HTTP GET http://192.168.43.102/fcmapi2/user
06-06 16:57:57.315  28383-28383/com.spartan D/WebClient﹕ {
    "error": {
    "message": "Invalid Access token.",
    "type": "AuthException",
    "code": 401
    }
    }

when the first request is made the server sends back cookies for authentication on the subsequent requests. but it seems the cookies are not saved. see the cookie count!

@smarek
Copy link
Member

smarek commented Jun 7, 2015

@griffins open up a new ticket please, don't append such questions to old tickets.

@android-async-http android-async-http locked and limited conversation to collaborators Jun 7, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants