简体   繁体   English

Json POST请求数据无法访问Play Framework 2中的服务器

[英]Json POST Request data don't get to server in Play Framework 2

Hey I'm struggling with that problem. 嘿,我正在努力解决这个问题。 The server gets the request but not the json that i transmit. 服务器获取请求但不是我传输的json。 I have searched in the threads, but found nothing that works for me. 我在线程中搜索过,但发现没有什么对我有用。

My Coffescript request: 我的Coffescript请求:

d = { 'filter': "John Portella" };

$.ajax(
  type: "POST",
  dataType: "text/json",
  data : JSON.stringify(d),
  url: "/restricted/actionOnMultipleDatasets",
  success: (data) ->
    ...

The related route: 相关路线:

POST   /restricted/actionOnMultipleDatasets       controllers.ajax.AjaxDatasetOperations.actionOnMultipleDatasets()

and the Controller action 和控制器的行动

@SecuredAction(authorization = WithProvider.class, params = { "userpassword" })
public static Result actionOnMultipleDatasets() {
    UserInfo userInfo = (UserInfo) ctx().args.get(SecureSocial.USER_KEY);
        JsonNode json=request().body().asJson();
    if(json==null){
        return badRequest(Json.toJson("Data is not Json!"));
    }

And every time I request that action the json is null. 每当我请求该动作时,json为空。 Does anyone figure out why this happens? 有没有人弄清楚为什么会这样? As additional information I use securesocial. 作为附加信息,我使用securesocial。

I have tried to clean up the project. 我试图清理这个项目。 Nothing happened. 没啥事儿。

The related stack trace: 相关的堆栈跟踪:

java.lang.NullPointerException
    at controllers.ajax.AjaxDatasetOperations.actionOnMultipleDatasets(AjaxDatasetOperations.java:588)
    at Routes$$anonfun$routes$1$$anonfun$applyOrElse$36$$anonfun$apply$36.apply(routes_routing.scala:497)
    at Routes$$anonfun$routes$1$$anonfun$applyOrElse$36$$anonfun$apply$36.apply(routes_routing.scala:497)
    at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183)
    at play.core.Router$Routes$$anon$1.invocation(Router.scala:377)
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56)
    at play.GlobalSettings$1.call(GlobalSettings.java:64)
    at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91)
    at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90)
    at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)
    at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:278)
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:274)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)
    at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

When posting with jquery, try adding the following lines as parameters: 使用jquery发布时,请尝试添加以下行作为参数:

contentType: "application/json; charset=utf-8", contentType:“application / json; charset = utf-8”,

dataType: "json", dataType:“json”,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM