最近我在發佈到我的REST接口上時發現驗證錯誤。 Content-Type: application/x-www-form-urlencoded
正在工作。使用Content-Type:multipart/form-data發佈結果爲空請求主體
這裏是我的測試功能:
/**
* @Rest\Route("/testtype")
*/
public function postTypeTestAction()
{
$request = $this->getRequest()->request->all();
$phpContents = file_get_contents("php://input");
return FOSView::create()->setStatusCode(200)->setData(array('request'=>$request, 'phpinput' => $phpContents));
}
發帖時使用Content-Type: application/x-www-form-urlencoded
:
{
"request":{
"test":"message"
},
"phpinput":"test=message"
}
發帖時使用Content-Type: multipart/form-data
:
{
"request":[
],
"phpinput":"------WebKitFormBoundaryFyQqAxqqfuhWzHUq\r\nContent-Disposition: form-data; name=\"test\"\r\n\r\nmessage\r\n------WebKitFormBoundaryFyQqAxqqfuhWzHUq--\r\n"
}
由於沒有請求數據,我得到This value should not be blank
驗證錯誤。這打破了我的申請。我一直盯着這麼久,我肯定我錯過了一些簡單的事情。
我使用Symfony 2.3.7和FOSRestBundle 1.0.0。