Note that there are some explanatory texts on larger screens.

plurals
  1. POClassCastException: BasicHttpResponse cannot be cast to org.apache.http.HttpEntity android
    text
    copied!<p>I am trying to send an http request to a server with a cookie attached to the httppost request as shown below.</p> <pre><code>public static void cookieRequest(String url, String cookie){ try { CookieStore cookieStore = new BasicCookieStore(); BasicClientCookie stdCookie = new BasicClientCookie("Cookie",cookie); cookieStore.addCookie(stdCookie); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); HttpPost httppost = new HttpPost(url); HttpResponse response = httpClient.execute(httppost, localContext); String result = EntityUtils.toString((HttpEntity) response); System.out.println("Cookie: "+ result); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } </code></pre> <p>But my log shows the following error. any idea ?</p> <pre><code> 11-21 14:04:23.330: W/System.err(3552): java.lang.ClassCastException: org.apache.http.message.BasicHttpResponse cannot be cast to org.apache.http.HttpEntity 11-21 14:04:23.335: W/System.err(3552): at packageapp.util.Utils.cookieRequest(Utils.java:635) 11-21 14:04:rop23.335: W/System.err(3552): at package.app.packageMenu$loadingTask.doInBackground(packageMenu.java:482) 11-21 14:04:23.340: W/System.err(3552): at package.app.packageMenu$loadingTask.doInBackground(packageMenu.java:1) 11-21 14:04:23.340: W/System.err(3552): at android.os.AsyncTask$2.call(AsyncTask.java:287) 11-21 14:04:23.345: W/System.err(3552): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 11-21 14:04:23.345: W/System.err(3552): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 11-21 14:04:23.345: W/System.err(3552): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 11-21 14:04:23.345: W/System.err(3552): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 11-21 14:04:23.345: W/System.err(3552): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 11-21 14:04:23.345: W/System.err(3552): at java.lang.Thread.run(Thread.java:856) </code></pre> <p><strong>update : this is my cookie [[version: 0][name: PHPSESSID][value: ec3e7cd62ae550880ecd25eb2b305d9e][domain: rec.m.package.com][path: /][expiry: null], [version: 0][name: lang][value: en][domain: .lpackagecom][path: /][expiry: Fri Nov 21 14:33:24 UTC+04:00 2014], [version: 0][name: ci_session][value: v0z%2F8ANEAAOV8rbnyBRz%2FBIt2kMHAjNb3n7fTwyYwS4DDaI9DVmiiKAJBZpdCZHf6zopLjkpACAmQvKMj2NBhTIhK4Lss9fPgZ7UGyK3ONGXsK0eXdWECIgVFWB1TSRx0QQ3%2BBtDFLWJ1I7g26j8D603TjzSnMnfejlFZFWRFMm9xGX7fiC3qNuucFJyNTulyYzqQbH%2FCUZjRHSwT8MkplPLr7q6WhKmtsidXCFiYX3mPtJpMHyQL374c%2BWT0QOp14Au3NnjtrQyCx5v%2BpJXgboXTFMD7cqTrIpjHNZCLx4AVKa1IdbeTNvYgIXSYx8uo8pfKIZcvYSZbbRcvHP%2FAA%3D%3D][domain: .package.com][path: /][expiry: Sat Nov 23 14:33:24 UTC+04:00 2013]]</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload