0

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.

Community
  • 1
  • 1
Shichao
  • 219
  • 1
  • 3
  • 14
  • How are you running the curl command? Directly from shell? I ask because it looks like something is removing the double quotes before curl sends the data. Another odd part is that the single quotes remain around the JSON. – Kurt Stutsman Oct 11 '11 at 12:06
  • I'm using windows, so I run the curl command from the command window. – Shichao Oct 11 '11 at 12:27
  • The whole return of var_dump($payload) is `string(34) "'{locationId:33,limit:5,offset:0}'"` – Shichao Oct 11 '11 at 12:33

1 Answers1

1

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
Kurt Stutsman
  • 3,994
  • 17
  • 23
  • Thanks, it helps. When I use command `curl -v -H "Content-Type: application/json" -X GET -d "{\"locationId\":\"33\",\"limit\":\"5\",\"offset\":\"0\"}" http://localhost/api/review`, it returns `string(44) "{"locationId":"33","limit":"5","offset":"0"}"`. – Shichao Oct 11 '11 at 13:02
  • However, is there any good tool for testing restful service that doesn't need to use '\' to escape special characters? – Shichao Oct 11 '11 at 13:04
  • The [curl manpage](http://curl.haxx.se/docs/manpage.html) says that `-d @filename` will let you upload the contents of a file. You could put the value exactly as you want to send it in a file and then upload that. – Kurt Stutsman Oct 11 '11 at 13:08
  • thanks for the help, also I just found a extension for Google Chrome called REST Console to test. – Shichao Oct 11 '11 at 13:17