* I tested with Curl command like this. curl --header "Content-type: application/json" --request POST --data '{"name": "Guillaume"}' http://localhost:8080/api/notifi => request().body().asJson() can get the json request value
* server-side source : // CREATE public static Result createNotification() { // String json = request().body().asText(); // System.out.println("json =" + json); // System.out.println("request().body().asFormUrlEncoded() =" + request().body().asFormUrlEncoded()); // String json = request().body().asJson().toString(); // Notification input = new Gson().fromJson(json, Notification.class); //input.save(); return ok(); } * routes : #POST /api/notification3 com.locket.notification.controllers.Notification3Ctl.createNotification() OPTIONS /api/notification3 com.locket.notification.controllers.Notification3Ctl.createNotification() * front-end source : var data = {"name": "Guillaume"}; $http({ url: 'http://localhost:8080/api/notification3', method: "POST", dataType: "json", data: data, headers: {'Content-Type': 'application/json'} }).success(function (data, status, headers, config) { debugger; console.log("good") }).error(function (data, status, headers, config) { debugger; console.log("something wrong") });
Comments
Post a Comment