I do a PUT
request but I cannot access the posted data, I always get string(0) ""
back.
The code I'm using for getting the PUT
data is:
public function editProduct($id) {
$put = file_get_contents('php://input',true);
return var_dump($put);
}
The PUT
request is
thanasisem@debian:~$ curl -i -X PUT -d arg=123 -d arg2=345 localhost/laravelproject/public/products/5
HTTP/1.1 200 OK
Date: Mon, 30 Jun 2014 17:22:59 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.4-14+deb7u11
Cache-Control: no-cache
X-Frame-Options: SAMEORIGIN
Set-Cookie: laravel_session=eyJpdiI6IjdcL3dYVlM1ZXZOZ0JHMVQrb1o1ME1sa3c3QTdTNnRXUnhxTWFDeHJSVDBJPSIsInZhbHVlIjoicTVPb2QwdThNRE1xUnh4VWZnWW5FT3ZTQUxKaE1RdWtycjNVUmlPWVZCZmVNcVBaVFY0Z0k1bEpSV0phVG5TckNWSkh1S2tsR1NEbmxvcFpna3lDOEE9PSIsIm1hYyI6ImI4ZmRlZTM1ODAyNDY3YjY5ZGQyZTE5NGZiMTEzZWVlOWUzZDIyZTI4MmE3MjM4MDM5NGFkZTRjOWQ4Yzk2OGQifQ%3D%3D; expires=Mon, 30-Jun-2014 19:22:59 GMT; path=/; httponly
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
string(0) ""
thanasisem@debian:~$
Solved.
I had to put -H 'Content-Type: application/json'
in my PUT
request in order for it to work.
A successful PUT
request that I created is the following:
curl -X PUT -H 'Content-Type: application/json' -d '{"firstName":"Kris", "lastName":"Jordan"}' localhost/laravelproject/public/products/5