我正在尝试将数据从 android 模拟器发送到在 localhost 上运行的 servlet,我有以下代码,但它没有向 servlet 发送数据。我也试过我的 ip "192.168.2.15:8080" 而不是 "10.0.2.2:8080" 但结果是一样的,谁能告诉我哪里错了?
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://10.0.2.2:8080/Interactive_ICS_Web/datareciever");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", "naveed"));
nameValuePairs.add(new BasicNameValuePair("password", "12345"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}