Post data to server in android
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.
精彩评论