玩框架路由麻烦(400错误请求) [英] play framework routes trouble (400 bad request)
问题描述
我在对Play框架进行POST时遇到了麻烦-可能与Play的关联性不如HTTP.
I'm having trouble making a POST to the play framework - this may not even be Play related as much as HTTP related.
$.ajax({
type:'POST',
url:'http://localhost:9000/start',
data: {
myJson:JSON.stringify(arg)
}
}).done(function(data) {
console.log(data);
});
其中,arg
是字符串数组,即:
['a', 'b', 'c']
where arg
is an array of strings, ie:
['a', 'b', 'c']
我试图用来捕获的路由是:
The route I'm trying to use to capture this is:
POST /start controllers.Application.startIt(myJson)
我做错了什么?截至目前(如果路线已正确捕获),该函数将永远不会返回400.Play控制台没有输出,只有javascript:
What am I doing wrong? As of right now (if the route is capturing correctly), that function will never return a 400. There is no output to the Play console, only javascript:
POST http://localhost:9000/start 400 (Bad Request)
推荐答案
文档说明了BadRequest何时出现错误代码由框架返回.问题来自您的路由器文件.您定义了一条路由/start ,该路由将触发方法调用 startIt ,但是该方法有一个参数,框架不知道应该传递哪个值.
The documentation explains when a BadRequest error code is returned by the framework. The problem comes from your router file. You define a route /start which will trigger a method call startIt, but the method has an argument and the framework does not know which value it should pass.
要正确处理JSON请求,请查看文档的专用部分
To handle correctly JSON requests, have a look to the dedicated part of the documentation.
这篇关于玩框架路由麻烦(400错误请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!