API localhost problem

I have a problem with Open Trivia API. It really simple API ( https://opentdb.com/api_config.php ) but it works on any server but not working localhost (it returns nothing).
I tried with other API’s and it seems all of them working on server but not on local machine.

I’m using XAAMP for local environment. Is there something in xaamp configuration that I need to change?

Thanks.

How do you try to get results from that API? Show code.
You also could try Postman to determine if it’s a problem with your local computer, like e.g. ports blocked.

I tried it in several ways to get results (curl, file_get_contents…). Here is one way:

$url = ‘https://opentdb.com/api.php?amount=10’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result);

But code is not problem, because same code works on any server (but not localhost).

Postman also normally retrieves data so i guess that’s fine.

CURL has some debug methods: https://www.php.net/curl_%20error

I’m not seeing an issue with the code itself. I’m at work so I can’t toss it local to see what it does, but can later.

Yes, code is fine. As I told before, it works on other servers but on local machine returns nothing.

As I said, I cant test it locally later tonight.

If it works on postman, and I can definitely navigate to the page, it may be an environmental issue with your localhost.

echo file_get_contents("https://opentdb.com/api.php?amount=10’");

Have you ever done cURL on your machine before? This is what I receive from the request.

Check your phpinfo for this section

No i didin’t done cURL on my computer (working on servers usually).
The results you’ve got is correct.
phpinfo is same like yours.

It’s really confusing that it’s not working.

Can you cURL to any other site? If not, I would suspect you’re missing something on your local.

No i cant. Yes that is sure, problem is on local environment, but not sure what.

It’s not cURL problem because i also tried with file_get_contents and it also doesn’t work.

Check your ini file setting for this key, allow_url_fopen. That’s a possible culprit, but I’m not sure where to go from there.

All I can think to do from here is to check the Apache error logs and see if something is happening there

Sponsor our Newsletter | Privacy Policy | Terms of Service