HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://recrutement.stb.com.tn:1010/PlateformeApi_Externe/api/Authorize/");
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList< NameValuePair >(5);
nameValuePairs.add(new BasicNameValuePair("username", "sami"));
nameValuePairs.add(new BasicNameValuePair("password", "stb"));
nameValuePairs.add(new BasicNameValuePair("AuthMethod", "FormsAuthentication"));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.d("myapp", "works till here. 2");
try {
HttpResponse response = httpclient.execute(httppost);
Log.d("myapp", "response " + response.getEntity());
String responseBody = EntityUtils.toString(response.getEntity());
Toast.makeText(MainActivity.this,"ok"+responseBody,Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
});
}}
android.os.NetworkOnMainThreadException