0
votes

I am having problems calling a url from PHP code. I need to call a service using a query string from my PHP code. If I type the url into a browser, it works ok, but if I use file-get-contents() to make the call, I get:

Warning: file_get_contents(http://...../cron.php?act=junoo): failed to open stream: HTTP request failed! in /home/..../..../.../userdat.php on line 37

The code I am using is:

    $junoo = json_decode(file_get_contents("http://.../cron.php?act=junoo"),true);
    $lan = $junoo['id'];
2

2 Answers

0
votes

You can use php curl lib to call API first and store the contents into a file. When you have the file, you can use your code with that file.

https://www.php.net/manual/en/curl.examples-basic.php

0
votes

Try following the networking request in the networking tab of the developer tools in your browser. The browser may have changed the connection to use https:// or redirected to another link. It is also possible that the request is missing cookie data that the browser already has stored.