1

我正在使用 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"
}

我该怎么做?那可能吗?有什么建议吗?

4

1 回答 1

1

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

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

这将包含发布到服务器的原始数据,如果它的 json 则需要解码

于 2015-05-24T04:34:42.247 回答