如何将post参数更改为json raw格式



我使用FOSRestBundle来构建Restful API。我有一个POST Restful服务的代码:

/**
 * Create a new session.
 * @param ParamFetcher $paramFetcher
 *
 * @ApiDoc(
 *   resource = true,
 *   https = true,
 *   description = "Create a new session",
 *   statusCodes = {
 *      200 = "Returned when successful",
 *      400 = "Returned when errors"
 *   }
 * )
 *
 * @RequestParam(name="username", nullable=false, strict=true, description="The username")
 * @RequestParam(name="veevaToken", nullable=false, strict=true, description="The token")
 * @RequestParam(name="instanceUrl", nullable=false, strict=true, description="The instance URL")
 *
 * @return View
 */
public function postSessionAction(ParamFetcher $paramFetcher)
{
     ....
}

我发送参数为x-www-form-urlencoded,我想将其更改为原始格式,例如:

{
  "veevaToken": "xxxxxx",
  "instanceUrl":"xxxxxx",
  "username":"xxxx"
}

我该怎么做?这可能吗?任何建议吗?

POST正常的原始格式,但在您的php中使用$_POST[name]而不是使用

   $http_raw = file_get_contents('php://input);

包含发送到服务器需要解码的原始数据如果是json

最新更新