node 서버에서 안드로이드에서 post로 보낸 json 문자열이 받아지지 않아요
글쓴이: dragonHu / 작성시간: 화, 2016/07/19 - 9:05오후
try {
JSONObject obj = new JSONObject();
obj.put("id", editid.getText().toString());
obj.put("pw", editpassword.getText().toString());
final String jsonstring = obj.toString();
//final String jsonstring = "{\"id=\":\"abce\",\"pw\":\"13447\"}";
Log.i("tag",jsonstring);
Thread background = new Thread(new Runnable() {
@Override
public void run() {
try {
Log.i("tag", "Thread 시작");
URL url = new URL("http://49.172.86.247:80/login/controller_on");
HttpURLConnection hey = (HttpURLConnection) url.openConnection();
hey.setRequestMethod("POST");
hey.setDoInput(true);
hey.setDoOutput(true);
hey.setRequestProperty("Content-Type", "application/json");
hey.setConnectTimeout(10000);
hey.setUseCaches(false);
DataOutputStream wr = new DataOutputStream(hey.getOutputStream());
InputStream inputStream = hey.getInputStream();
Log.i("tag", "write");
wr.writeBytes(jsonstring);
Log.i("tag", "flush");
wr.flush();
Log.i("tag", "close");
wr.close();
} catch (Exception e) {
Log.e("tag","error");
}
}
});
background.start();
} catch (JSONException e) {
e.printStackTrace();
}안드로이드에서 위와 같이 post 방식으로 json 문자열을 보냈는데요 wr.writeBytes(jsonstring); 부분부터 실행되지가 않습니다.
노드 서버에서는 아래와 같이 데이터를 받았습니다.
app.post('/login/:termType', function(req, res){
console.log(req.body);
});html에서 form 태그를 이용해서 보낼땐 잘 전달되는데 안드로이드에서 보내는 결과는 항상 {}만 나옵니다.
어느 곳이 문제인지 잘 모르겠습니다. 조언부탁드려요 .
Forums:


댓글 달기