最近我在发布到我的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。