![](/img/trans.png)
[英]How to get httpOnly cookies from android.webkit.CookieManager
[英]why the cookies of cookieManager is differenet from cookies of httpClient In Android?
我正在为Android编写一个程序,使用HttpClient
将一些POST
发送到webService,如下所示:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://example.com/service");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("email", email));
nameValuePairs.add(new BasicNameValuePair("password", password));
// Execute HTTP Post Request
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String response = httpclient.execute(httppost , responseHandler) ;
我试图检索名为“ Form”的“ www.example.com” cookie,如下所示:
`
Log.d("Cookie0" , httpclient.getCookieStore().getCookies().get(0).getValue()) ;
Log.d("Cookie1", CookieManager.getInstance().getCookie("http://example.com"));
但是,两种检索Cookie的方法都会为“ Form”返回两个不同的值! 为什么?
根据文档, CookieManager
用于CookieManager
中的cookie:
管理应用程序的WebView实例使用的cookie
因此,如果您想从请求中获取Cookie,则httpclient.getCookieStore()
应该是正确的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.