When I send a PUT request to my Phalcon server with body encoded as form-data, fetching the data in the backend shows unexpected behaviour. For example:
I'm sending PUT with body as form-data:
PUT /test/phalconput/40 HTTP/1.1 Host: testphalconputserver.local Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW Authorization: Bearer avalidtoken Cache-Control: no-cache Postman-Token: 1ae28de5-bf7a-4b20-9156-548d077a4c1a
------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="param1"
value1 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="param2"
value2 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="param3"
In backend I fetch like this:
var_dump($this->request->getPut());
And the result is one array with one big string and alot of 'noise':
array (size=1) '----------------------------011430535261077664402366 Content-Disposition:_form-data;_name' => string '"param1"
value1 ----------------------------011430535261077664402366 Content-Disposition: form-data; name="param2"
value2 ----------------------------011430535261077664402366 Content-Disposition: form-data; name="param3"
The following:
$this->request->getPut('param1'); $this->request->getPut('param2');
return null. This is clearly unintended behaviour.
When you do the same with getPost you get a nice formatted result. A workaround for the getPut method is to send the request encoded as x-www-form-urlencoded. The problem with this encoding is you cannot send files easily.
Any way to resolve this without swithing to x-www-form-urlencoded, pasing that big string myself or changing the request to POST?