• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps HTTP 1.1 Bad Request while trying to send a cookie with a HttpGet request


Aug 17, 2012
I am developing an Android app for a website. I'm trying to get some information from the website by sending a cookie using a HttpGet request. I don't know where I am going wrong with the request. I am using AsyncTask to send the request to the server.
The request also uses a token which I receive when I login to the webpage. All this is clear in the code below. This is part of the process in the doInBackground() function of the Asynctask:

BufferedReader in = null;

JSONObject token = Login.getToken(); // Token received after login, used in the cookie

try {
r = token.get("session_token").toString();
} catch (JSONException e) {
// TODO Auto-generated catch block

DefaultHttpClient httpclient = (DefaultHttpClient) getHttpClient();

BasicClientCookie ck = new BasicClientCookie("session_token", r);

// Create a local instance of cookie store
CookieStore cookieStore = new BasicCookieStore();

// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context


localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

HttpGet httpget = new HttpGet("http://example.com/api/page");

try {

HttpResponse response = httpclient.execute(httpget, localContext);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

StringBuilder builder = new StringBuilder();
String line=null;

for (line = null; (line = in.readLine()) != null;) {

The getHttpClient function looks like:

public static final int HTTP_TIMEOUT = 30 * 1000;

private HttpClient mHttpClient;

private HttpClient getHttpClient() {
if (mHttpClient == null) {
mHttpClient = new DefaultHttpClient();
final HttpParams params = mHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
return mHttpClient;

If somebody could please help me out. It would be great.


We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.