gpt4 book ai didi

android - ClassCastException : BasicHttpResponse cannot be cast to org. apache.http.HttpEntity 安卓

转载 作者:行者123 更新时间:2023-11-30 03:16:04 25 4
gpt4 key购买 nike

我正在尝试向服务器发送一个 HTTP 请求,并在 httppost 请求上附加一个 cookie,如下所示:

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();
}

}

但是我的日志显示如下错误:

    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)

有什么想法吗?

更新:这是我的 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]]

最佳答案

试试这个

EntityUtils.toString(response.getEntity())

关于android - ClassCastException : BasicHttpResponse cannot be cast to org. apache.http.HttpEntity 安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20117936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com