简体   繁体   English

从Android向Servlet发送数据

[英]Sending data to servlet from android

I am trying to send data from android emulator to servlet running on localhost, I have following code, but its not sending data to servlet. 我正在尝试将数据从android仿真器发送到在localhost上运行的servlet,我有以下代码,但它没有将数据发送到servlet。 I have also tried my ip "192.168.2.15:8080" instead of "10.0.2.2:8080" but result is same, could anyone please tell me where I am wrong? 我也尝试了我的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
}

Problem solved, it was my stupidness. 问题解决了,这是我的愚蠢。 I was using httppost in android code, and trying to receive in doGet() on servlet 我在Android代码中使用httppost,并尝试在servlet的doGet()中接收

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM