[英]android and node.js
我試圖通過我的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();
}
檢查事項:
http://192.168.1.100:8080/
嗎? ( 在cURL或通過網絡瀏覽器中嘗試 ) 如果#1或#2失敗,則問題是配置問題。 否則,我至少會包含錯誤消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.