最近,我在使用Content-Type: multipart/form-data
. Content-Type: application/x-www-form-urlencoded
正在工作中。
这是我的测试功能:
/**
* @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));
}
当我使用 POST 时Content-Type: application/x-www-form-urlencoded
:
{
"request":{
"test":"message"
},
"phpinput":"test=message"
}
当我使用 POST 时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。