android app
에서 play framework 1.2.5
웹 서비스로 데이터 매개 변수 json
을 요청해야합니다. 나는 평범한 매개 변수를 핵심 가치로 보냄으로써 그것을 할 수 있었다. 하지만 json 개체로 이러한 매개 변수를 보내고 싶습니다. 나는 routes
에 URL을 정의하는 방법을 알지 못하며 컨트롤러의 정적 함수는 play framework 1.2.5
에서 json 요청을 처리 할 수 없다.재생 프레임 워크에서 json 요청을 처리하는 방법 1.2.5
public ConnectService(String sngUrl,String searchkey,Double longitude,Double latitude,Double radius){
try {
jsonObject.put("searchkey", searchkey);
jsonObject.put("longitude", longitude);
jsonObject.put("latitude", latitude);
jsonObject.put("radius", radius);
} catch (JSONException e) {
System.out.println("HATA 1 : "+e.getMessage());
e.printStackTrace();
}
jArrayParam = new JSONArray();
jArrayParam.put(jsonObject);
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("jsonRequest", jsonObject.toString()));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(sngUrl);
httppost.addHeader("Content-Type", "application/json");
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePair,"UTF-8"));//HTTP.UTF_8
System.out.println("URLLLLLLLL : "+httppost.getRequestLine());
response = httpclient.execute(httppost);
entity = response.getEntity();
} catch (UnsupportedEncodingException e) {
System.out.println("HATA 2 : "+e.getMessage());
e.printStackTrace();
} catch (ClientProtocolException e) {
System.out.println("HATA 3 : "+e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.out.println("HATA 4 : "+e.getMessage());
e.printStackTrace();
}
finally{
}
}
그리고 여기 난 당신이 재생 응용 프로그램에서 선언 경로 및 행동에 잘못이 있다고 생각 내 경로와 제어 방법
POST /search Application.search(jsonRequest)
//not for json request
public static void searchproduct(String searchkey,Double longitude,Double latitude,Double radius){
String d=searchkey+" "+longitude+" "+latitude+" "+radius ;
renderJSON(d);
}
감사합니다. httppost 헤더에서도 실수를했습니다. 나는이 httppost.addHeader ("Content-Type", "application/x-www-form-urlencoded")와 같아야했다. – demlik