Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server not Recognising Cookie From Android Phone

I am trying to connect to a drupal server. I have been able to do this in the past but the drupal developers now require me to add another cookie. The server does not register the cookie that I am trying to send below. Can anybody see why?

public static void maybeCreateHttpClient() {
    if (mHttpClient == null) {
        mHttpClient = new DefaultHttpClient();
        final HttpParams params = mHttpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(params,
            REGISTRATION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT);
        ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT);



        BasicCookieStore cookieStore = new BasicCookieStore();
        ClientCookie cookie = new BasicClientCookie("aml", key);

        cookieStore.addCookie(cookie);

        localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);


    }
}
like image 715
jiduvah Avatar asked Nov 18 '11 15:11

jiduvah


1 Answers

It turns out that, I didn't need to use cookie, cookstore or httpcontent. As far as I can understand these are mainly used to managed cookies coming from the server.

I managed to solve my problem by setting a header like so

    String key = "whatever";

    post.addHeader("Cookie", "aml=" + key);

This can be used on httppost, httpget or httput.

That took me a few days for such a simple solution. I hope it helps somebody else out

like image 168
jiduvah Avatar answered Oct 20 '22 06:10

jiduvah