Receive JSON data with Curl

Asked

Viewed 5,879 times

2

I’m sending a Curl to a URL that will return a JSON as a response. By the browser, accompanying with firebug, the return is in JSON, but when I do the same procedure by PHP, it returns a page (which seems to have been processed with the return of JSON), so much so that if I put curlopt_followlocation, false page return is blank.

How do I get the page back in JSON? I tried something like: curlopt_httpheader, array("accept: application/json") and unsuccessfully.

I have an X page, where I get the answer from the Y page (where I use Curl), on page X the return of page Y comes in HTML instead of JSON, and when I tell Curl not to follow any followlocation the page comes back blank.

I would not like to do via AJAX, but in PHP.

1 answer

3

Alexandre hope it helps.

I have this script running smoothly.

$url = "http://www.url.com.br";

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);

curl_close($ch);

var_dump(json_decode($result, true));

If it doesn’t help, put the code you’re trying to so we can evaluate it better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.