2

My post request looks like this:

Request URL:http://localhost:9000/getjson?_dc=1381814841666
Request Method:POST

It is generated by Extjs. And my routes is as following:

POST        /getjson{?_dc=<[0-9]+>para}                 controllers.Application.getjson(para:String)

and my controller is :

object Application extends Controller {

  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }
  def sidebar = Action {
    Ok(views.html.sidebar("SBide Bar"))
  }
  def showerr(info:String) = Action {
    Ok(views.html.showerr(info))
  }
  // how to cooperate with extjs ?
  def getjson(para:String) = Action(parse.json) { request =>  {
      val jsval: JsValue = request.body
      val w = new PrintWriter(new File("test.txt" ))
      w.write("json: %s".format(jsval.asOpt[String]))
      w.close()

      Ok("get json "+para)
    }
  }
}

but the server seems can't find a match for the post, it response with:

Action not found
For request 'POST /getjson?_dc=1381814841666'
These routes have been tried, in this order:
1 GET / controllers.Application.index
2 GET /sidebar controllers.Application.sidebar
3 GET /error/$info<.+> controllers.Application.showerr(info:String)
4 POST /getjson{?_dc=<[0-9]+>para} controllers.Application.getjson(para:String)
5 GET /assets/$file<.+> controllers.Assets.at(path:String = "/public", file:String)

How should i fix it? Can anyone see what's the matter?

--EDIT

I tried the route for test:

GET / test$para<%3f_dc=[0-9]+> controllers.Application.test(para:String)

it only worked for url like that: /test%3f_dc=123, not for /test?_dc=123. I also tried to replace %3f as \? in the regex part, it complied successfully but still can't work.

so HOW should I write the route for urls that contains a ? ?

--EDIT2

I changed route to the following:

POST /getjson$para<.*> controllers.Application.getjson(para:String)

Now the route worked, but the para I got is empty! Most impoortant is the request.body is None! however, from chrome Audits, I can see the json is already in Request Payload, so WHAT I WAS MISSED ?

4

1 回答 1

0

这只能以这种方式工作:

路线:

POST /getjson/$_dc<[0-9]+> controllers.Application.getjson(_dc:String)

你应该这样称呼它:

http://localhost:9000/getjson/1381814841666

不幸的是,我没有找到使它与查询参数一起工作的方法。希望这对你有用

于 2013-10-15T06:35:27.377 回答