2010-11-01 55 views
3

我想通过android中的POST方法将一些数据发送到服务器。我正在使用下面的代码将数据发布到android中的服务器

DefaultHttpClient hc=new DefaultHttpClient(); 
ResponseHandler <String> res=new BasicResponseHandler(); 
HttpPost postMethod=new HttpPost(url); 
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
nameValuePairs.add(new BasicNameValuePair("name", "value"));  
nameValuePairs.add(new BasicNameValuePair("password", "value"));  
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
String response=hc.execute(postMethod,res); 

但我在我的响应XML获取错误响应。错误消息是Cookie在客户机中被禁用。我如何需要在android中启用cookie?

+0

请将代码放在代码块中。 – xandy 2010-11-01 07:53:23

回答

1

您需要根据您的请求处理cookie。请参阅thisthis相关问题。

+0

你好朋友,我得到的cookie大小是0,当我使用CookieStore对象的getCookie方法打印cookie时。我可以知道在哪里查找cookie值以及如何在发送请求时设置这些值。即使我使用给定的示例,我也会在我的响应xml正文中得到相同的响应“客户端计算机中的cookie被禁用”。 – Senthil 2010-11-01 11:29:15

相关问题