【问题标题】:Post data to server in android在android中将数据发布到服务器
【发布时间】:2011-05-03 07:30:37
【问题描述】:

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

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?

【问题讨论】:

  • 请将您的代码放入代码块中。

标签: android post cookies


【解决方案1】:

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

【讨论】:

  • 你好朋友,当我使用 CookieStore 对象的 getCookie 方法打印 cookie 时,我得到的 cookie 大小为 0。我可以知道在哪里可以找到 cookie 值以及如何在发送请求时设置这些值。即使我使用那里给出的示例,我也会在我的响应 xml 正文中得到相同的响应“cookies are disabled in client machine”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多