0

I am using code like this:

echo file_get_contents('https://example.com/file.txt');

In response I get an error:

Warning: file_get_contents(https://example.com/file.txt): failed to open stream: Cannot assign requested address in /sites/example.com/test.php on line 2

As I understand it, the server for some reason forbids accessing the file_get_contents () function if the file is located on the same server. Because queries like this work:

echo file_get_contents('https://example.org');

Help me please. In which direction to dig?

  • https://stackoverflow.com/questions/697472/php-file-get-contents-returns-failed-to-open-stream-http-request-failed . use CURL or urlencode – Anant Kumar Singh May 25 '22 at 12:55

1 Answers1

-1

in /etc/hosts file

127.0.1.1 example.com example

replaced by

external_ip of example.com example