REST を初めて使用し、JSON 文字列を REST リクエスト URL のパス変数として送信しようとしています。クライアントからリクエストを送信するために行っていること:
JSONObject json = new JSONObject();
try {
json.put("Test", "123");
json.put("tracks", "1234");
jj = json.toString();
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String url = "http://localhost:8090/webApp/restresource/"+jj+".do";
st = (String) restTemplate.postForObject(url,jj, String.class, jj);
残りのサーバー:
@RequestMapping(value = "/restresource/{code}", method=RequestMethod.POST, consumes= "application/json")
public @ResponseBody String useJson(@PathVariable String jj) {
String result;
JSONObject jObject = new JSONObject();
try {
result = jObject.getJSONObject(jj).toString();
} catch (JSONException jse) {
jse.printStackTrace();
}
return result;
}
私が得る例外はnot enough variable values to expand "Test"
編集:私のリクエストURLは次のようになります:
http://localhost:8090/app/restResource/%7B%22%22:%22123%22,%22tracks%22:%221234%22%7D.do
HttpClientErrorException も見ました! どんな助けでも大歓迎です!