开发者

Restful request body return wrong JSON format when using getRawBody() in Zend framework

开发者 https://www.devze.com 2023-04-12 09:54 出处:网络
I\'m testing the restful service built with zend framework. I\'m using the command below to test it (learned from this post).

I'm testing the restful service built with zend framework. I'm using the command below to test it (learned from this post).

curl -v -H "Content-Type: application/json" -X GET -d '{"locationId":"33","limit":"5开发者_开发问答","offset":"0"}' \ http://localhost/api/review

But when I fetch the request body in Zend using $payload = $this->getRequest()->getRawBody();, the var_dump($payload) returns "'{locationId:33,limit:5,offset:0}'", where the double quotation marks are removed so that I can't decode it into array.

What's reason of it? Please help. Thank s in advance.


The Windows command line is removing the double quotes. It also does not recognize single quotes. You can try double quoting the entire thing and escaping the quotes use internally like this:

curl -v -H "Content-Type: application/json" -X GET -d "{\"locationId\":\"33\",\"limit\":\"5\",\"offset\":\"0\"}" http://localhost/api/review
0

精彩评论

暂无评论...
验证码 换一张
取 消