繁体   English   中英

为什么cookieManager的cookie与Android中的httpClient的cookie不同?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM