[英]POSTing with Content-Type: multipart/form-data results in empty request body
Recently I started getting validation errors when POSTing to my REST interface with Content-Type: multipart/form-data
. 最近,当我使用
Content-Type: multipart/form-data
到REST接口时,我开始收到验证错误。 Content-Type: application/x-www-form-urlencoded
is working. Content-Type: application/x-www-form-urlencoded
正在运行。
Here is my testing function: 这是我的测试功能:
/**
* @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));
}
When I POST using Content-Type: application/x-www-form-urlencoded
: 当我使用
Content-Type: application/x-www-form-urlencoded
:
{
"request":{
"test":"message"
},
"phpinput":"test=message"
}
When I POST using Content-Type: multipart/form-data
: 当我使用
Content-Type: multipart/form-data
:
{
"request":[
],
"phpinput":"------WebKitFormBoundaryFyQqAxqqfuhWzHUq\r\nContent-Disposition: form-data; name=\"test\"\r\n\r\nmessage\r\n------WebKitFormBoundaryFyQqAxqqfuhWzHUq--\r\n"
} }
Since there is no request data, I'm getting This value should not be blank
validation errors. 由于没有请求数据,因此我得到
This value should not be blank
验证错误。 This breaks my application. 这破坏了我的应用程序。 I've been staring at this for so long, I'm certain I'm missing something simple.
我已经盯着看了这么久了,可以肯定我缺少一些简单的东西。
I'm using Symfony 2.3.7 and FOSRestBundle 1.0.0. 我正在使用Symfony 2.3.7和FOSRestBundle 1.0.0。
The issue resolved itself literally overnight. 这个问题实际上在一夜之间解决了。 No server reboot, no change to code, and I'm using the same tool to test ( DHC by Restlet - a Chrome extension).
没有重新启动服务器,没有更改代码,而且我正在使用同一工具进行测试( Restlet的DHC -Chrome扩展程序)。 However, since this was not working on both dev and staging environments, and is now working on both environments, this leaves me with the only answer being the testing tool, Chrome, a local caching issue or some combination.
但是,由于这在开发环境和暂存环境中均不起作用,而现在在两种环境中均有效,因此,唯一的答案就是测试工具,Chrome,本地缓存问题或某种组合。
Lesson learned: use multiple testing tools. 获得的经验:使用多种测试工具。
Now when I POST using Content-Type: application/x-www-form-urlencoded
: 现在,当我使用
Content-Type: application/x-www-form-urlencoded
:
{
"request":{
"test":"message"
},
"phpinput":"test=message"
}
Now when I POST using Content-Type: multipart/form-data
: 现在,当我使用
Content-Type: multipart/form-data
:
{
"request":{
"test":"message"
},
"phpinput":""
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.