我试图通过我的 android 客户端连接到 nodejs 服务器,但我什至无法建立连接.. 我试图按照一些教程进行操作,但徒劳无功.. 如何将 json 对象发送到 nodejs 服务器..
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();
}