1

我正在尝试将数据从 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
}
4

1 回答 1

0

问题解决了,这是我的愚蠢。我在 android 代码中使用 httppost,并尝试在 servlet 上的 doGet() 中接收

于 2012-09-23T12:43:56.620 回答