I am trying to read in a JSON message in my PHP app and this is my php code:
$json = file_get_contents('php://input');
$obj = json_decode($json, TRUE);
echo $obj->{'S3URL'};
When I do this I am getting the following error:
Trying to get property of non-object in setImage.php on line 25 (line 25 is the echo $obj->{'S3URL'}; line)
This is the request body of the request to the page:
Request Url: http://localhost:8888/setImage.php
Request Method: POST
Status Code: 200
Params: {
"S3URL": "http://url.com"
}
This is the request headers:
Accept: application/json
Content-Type: application/json
Connection: keep-alive
Origin: chrome-extension: //rest-console-id
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML,
However, if I instead echo out the $json
variable I get the following:
S3URL=http%3A%2F%2Furl.com
So it looks like file_get_contents('php://input');
is reading it in as a string, and not as JSON, which will make parsing it more difficult.
Any idea why it isn't being returned as JSON, or how I can get it to be returned as JSON?