I’m writing a program for Android that sends some POST to a webService with HttpClient like this :
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) ;
And I tried to retrieve a cookie of “www.example.com” called “Form” like this:
`
Log.d("Cookie0" , httpclient.getCookieStore().getCookies().get(0).getValue()) ;
Log.d("Cookie1", CookieManager.getInstance().getCookie("http://example.com"));
but the two methods of retrieving a cookie returns two different values for “Form” !
why?
According to the documentation
CookieManageris used for cookies in WebViews:So if you want to get the cookie from your request
httpclient.getCookieStore()should be the right way.