I am trying to call a servlet in Tomcat running on local from android app. I am not sure if it is reaching the servlet, because I don't see any system printout from the servlet. When I hit the url on the browser, I see something, but not from android app.
I have this in my AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Here is my code.
HttpClient client = new DefaultHttpClient();
HttpPost method = new HttpPost("http://192.168.1.6:8080/sampleweb/request");
List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>();
nameValuePairs.add(new BasicNameValuePair("req", xml));
method.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = (BasicHttpResponse) client.execute(method);
InputStream ips = response.getEntity().getContent();
BufferedReader buf = new BufferedReader(new InputStreamReader(ips, "UTF-8"));
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new Exception(response.getStatusLine().getReasonPhrase());
}
StringBuilder sb = new StringBuilder();
String s;
while (true) {
s = buf.readLine();
if (s == null || s.length() == 0)
break;
sb.append(s);
}
buf.close();
ips.close();
System.out.println("response="+sb.toString());
client.getConnectionManager().shutdown();