I want to send data from my android app to servlet. i was trying to use this in my app :
private boolean postData(String s) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(s); // s is my url
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", "1003"));
nameValuePairs.add(new BasicNameValuePair("name", "Anil"));
nameValuePairs.add(new BasicNameValuePair("loc", "Kalyan"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) {
// TODO Auto-generated catch block
return false;
}
return true;
}
I was this method but was not able to import these files :
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
How to impoert these files in android studio?? Or else is there any other method to do so?? Thanx in advance