다음과 같이 POST로 JSONObject를 서버로 전송합니다.
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost(url);
String json = "";
// 4. convert JSON to String
json = jsonObject.toString();
Log.d("json", "json: "+json);
// 5. set json to StringEntity
StringEntity se = new StringEntity(json);
// 6. set httpPost Entity
httpPost.setEntity(se);
// 7. Set some headers to inform server about the type of the content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json");
// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);
JSONObjcet는 테스트를 위해서 아래와 같은 오브젝트가 전송 되었다고 했을 때..
jsonObject.accumulate("timeStamp", "time");
jsonObject.accumulate("id", "test");
JSP 서버에서 받은 데이터를 확인해보려 하는데,
간단하게 request.getParameter("id") 로 시도해보면 null이 나오고
<%
String recv;
String recvbuff = "";
BufferedReader buffread = new BufferedReader(new InputStreamReader(request.getInputStream()));
while ((recv = buffread.readLine()) != null)
recvbuff += recv;
application.log("receive data: "+recvbuff);
buffread.close();
%>
위와 같이 하여도 recvbuff는 ""가 나옵니다..
이렇게 하면 전송된 오브젝트를 얻을 수 있는지 조언 부탁드립니다..
감사합니다!