开发者

Post data to server in android

开发者 https://www.devze.com 2023-01-23 11:29 出处:网络
I want to send some data to a server through POST method in android. I am using the following code DefaultHttpClient hc=new DefaultHttpClient();

I want to send some data to a server through POST method in android. I am using the following code

DefaultHttpClient hc=new DefaultHttpClient();  
ResponseHandler <String> res=new BasicResponseHandler开发者_JS百科();  
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); 

But I am getting the error response in my response xml. The error message is cookies are disabled in client machine. How do I need to enable cookies in android ?


You need to handle cookies with your request. See this and this related questions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号