Http 获取POST参数和标题

Http 获取POST参数和标题,http,scala,playframework-2.1,Http,Scala,Playframework 2.1,我有一个RESTFul API服务,我想在POST请求中获取参数(和头)。目前没有这方面的信息 我说的是,我有RESTfulAPI服务,我的意思是其中没有查看页面 我该怎么做?那是因为你想要的东西在里面 更多关于 或者,如果您只需要param: def myApiCall(param:String) = Action { //stuff with param Ok("...") } 对于这两种情况,路线如下所示: POST /myapicall/:param WhateverClass

我有一个RESTFul API服务,我想在POST请求中获取参数(和头)。目前没有这方面的信息

我说的是,我有RESTfulAPI服务,我的意思是其中没有查看页面


我该怎么做?

那是因为你想要的东西在里面

更多关于

或者,如果您只需要param:

def myApiCall(param:String) = Action {
  //stuff with param
  Ok("...")
}
对于这两种情况,路线如下所示:

POST /myapicall/:param WhateverClass.myApiCall(param)
  • 注意:将myApiClass重命名为myApiCall,这是最初的意图

    • 那是因为你想要的东西在里面

      更多关于

      或者,如果您只需要param:

      def myApiCall(param:String) = Action {
        //stuff with param
        Ok("...")
      }
      
      对于这两种情况,路线如下所示:

      POST /myapicall/:param WhateverClass.myApiCall(param)
      
      • 注意:将myApiClass重命名为myApiCall,这是最初的意图

        • 那是因为你想要的东西在里面

          更多关于

          或者,如果您只需要param:

          def myApiCall(param:String) = Action {
            //stuff with param
            Ok("...")
          }
          
          对于这两种情况,路线如下所示:

          POST /myapicall/:param WhateverClass.myApiCall(param)
          
          • 注意:将myApiClass重命名为myApiCall,这是最初的意图

            • 那是因为你想要的东西在里面

              更多关于

              或者,如果您只需要param:

              def myApiCall(param:String) = Action {
                //stuff with param
                Ok("...")
              }
              
              对于这两种情况,路线如下所示:

              POST /myapicall/:param WhateverClass.myApiCall(param)
              
              • 注意:将myApiClass重命名为myApiCall,这是最初的意图

                • 以下是一个小例子:

                  路线:

                  GET        /user/:name     controllers.Application.getUserInfo(name)
                  
                  在Application.scala中

                  object Application extends Controller {
                  
                  import play.api.libs.json._
                  import scala.reflect.runtime.universe._
                  
                  /**
                     * Generates a Json String of the parameters.
                     * For example doing getJson(("status" -> "success")) returns you a Json String:
                     * """
                     * {
                     *   "status" : "success"
                     * }
                     */
                  def getJson[T: Writes](pairs: (String, T)*): String = {
                      val i = pairs.map { case (x, y) => (x -> (y: Json.JsValueWrapper)) }
                      Json.obj(i: _*).toString
                    }
                  
                  def getUserInfo(name:String) = Action{ implicit request =>
                      val user = //get User object of name
                      Ok(getJson(("firstName" -> user.firstName),("lastName" -> user.lastName)))
                  }
                  //Directly calling Json.obj(("firstName" -> user.firstName),("lastName" -> user.lastName)).toString() will also do.  getJson is used to make it more readable.
                  

                  下面是一个小例子:

                  路线:

                  GET        /user/:name     controllers.Application.getUserInfo(name)
                  
                  在Application.scala中

                  object Application extends Controller {
                  
                  import play.api.libs.json._
                  import scala.reflect.runtime.universe._
                  
                  /**
                     * Generates a Json String of the parameters.
                     * For example doing getJson(("status" -> "success")) returns you a Json String:
                     * """
                     * {
                     *   "status" : "success"
                     * }
                     */
                  def getJson[T: Writes](pairs: (String, T)*): String = {
                      val i = pairs.map { case (x, y) => (x -> (y: Json.JsValueWrapper)) }
                      Json.obj(i: _*).toString
                    }
                  
                  def getUserInfo(name:String) = Action{ implicit request =>
                      val user = //get User object of name
                      Ok(getJson(("firstName" -> user.firstName),("lastName" -> user.lastName)))
                  }
                  //Directly calling Json.obj(("firstName" -> user.firstName),("lastName" -> user.lastName)).toString() will also do.  getJson is used to make it more readable.
                  

                  下面是一个小例子:

                  路线:

                  GET        /user/:name     controllers.Application.getUserInfo(name)
                  
                  在Application.scala中

                  object Application extends Controller {
                  
                  import play.api.libs.json._
                  import scala.reflect.runtime.universe._
                  
                  /**
                     * Generates a Json String of the parameters.
                     * For example doing getJson(("status" -> "success")) returns you a Json String:
                     * """
                     * {
                     *   "status" : "success"
                     * }
                     */
                  def getJson[T: Writes](pairs: (String, T)*): String = {
                      val i = pairs.map { case (x, y) => (x -> (y: Json.JsValueWrapper)) }
                      Json.obj(i: _*).toString
                    }
                  
                  def getUserInfo(name:String) = Action{ implicit request =>
                      val user = //get User object of name
                      Ok(getJson(("firstName" -> user.firstName),("lastName" -> user.lastName)))
                  }
                  //Directly calling Json.obj(("firstName" -> user.firstName),("lastName" -> user.lastName)).toString() will also do.  getJson is used to make it more readable.
                  

                  下面是一个小例子:

                  路线:

                  GET        /user/:name     controllers.Application.getUserInfo(name)
                  
                  在Application.scala中

                  object Application extends Controller {
                  
                  import play.api.libs.json._
                  import scala.reflect.runtime.universe._
                  
                  /**
                     * Generates a Json String of the parameters.
                     * For example doing getJson(("status" -> "success")) returns you a Json String:
                     * """
                     * {
                     *   "status" : "success"
                     * }
                     */
                  def getJson[T: Writes](pairs: (String, T)*): String = {
                      val i = pairs.map { case (x, y) => (x -> (y: Json.JsValueWrapper)) }
                      Json.obj(i: _*).toString
                    }
                  
                  def getUserInfo(name:String) = Action{ implicit request =>
                      val user = //get User object of name
                      Ok(getJson(("firstName" -> user.firstName),("lastName" -> user.lastName)))
                  }
                  //Directly calling Json.obj(("firstName" -> user.firstName),("lastName" -> user.lastName)).toString() will also do.  getJson is used to make it more readable.
                  


                  myApiClass的路由是什么样子的?如何查找头及其值?我尝试了
                  request.headers.keys.find(==“myHeader”)
                  ,但没有意义。老兄,你的问题已经得到了回答。我想现在是RTFM时间了。。。或者,如果您需要培训,我可以向您指出我的链接个人资料。很好,您认识到:)myApiClass的路由是什么样子的?我如何找到标头及其值?我尝试了
                  request.headers.keys.find(==“myHeader”)
                  ,但没有意义。老兄,你的问题已经得到了回答。我想现在是RTFM时间了。。。或者,如果您需要培训,我可以向您指出我的链接个人资料。很好,您认识到:)myApiClass的路由是什么样子的?我如何找到标头及其值?我尝试了
                  request.headers.keys.find(==“myHeader”)
                  ,但没有意义。老兄,你的问题已经得到了回答。我想现在是RTFM时间了。。。或者,如果您需要培训,我可以向您指出我的链接个人资料。很好,您认识到:)myApiClass的路由是什么样子的?我如何找到标头及其值?我尝试了
                  request.headers.keys.find(==“myHeader”)
                  ,但没有意义。老兄,你的问题已经得到了回答。我想现在是RTFM时间了。。。如果你需要培训,我也可以给你指一下我的个人资料。很好,你知道:)这不是发帖请求。这不是发帖请求。这不是发帖请求。这不是发帖请求。这不是发帖请求。