Im trying to connect to a nodejs server through my android client but i cant even make the connection.. I tried to follow some tutorials but in vain.. How can i send a json object to the nodejs server..
try{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost();
request.setHeader("Content-type", "application/json");
URI uri = new URI("http://192.168.1.100:8080/");
request.setURI(uri);
JSONObject json = new JSONObject();
Log.i("request", "OBject made");
json.put("users", et.getText().toString());
StringEntity se = new StringEntity(json.toString());
Log.i("request", "String Entity made");
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
request.setEntity(se);
Log.i("request", "Set String Entity made");
HttpResponse response = httpClient.execute(request);
tv.setText(response.getEntity().getContent().toString());
}
catch(Exception ex)
{
ex.printStackTrace();
}
Things to check:
http://192.168.1.100:8080/
? (try it in cURL or via a web-browser)If #1 or #2 fail, then the issue is a configuration issue. Otherwise, I would at least include the error message.