Web server on Linux with php 7.4 fails on file_get_contents() for 1 URL only

74 views Asked by At

I have problem using file_get_contents() for 1 particular URL only. I have full access to both the source and fetching server.

The following ARE set:

On getting server allow_url_fopen = On

On source server Header set Access-Control-Allow-Origin "*"

This is the source data I am trying to get. https://dataflexlink.tech/rest/plugin-info/ You can see in the headers that Access-Control-Allow-Origin is *

In fact, in this fiddle you can see that source goes over ajax on a completely different server without a problem.

This is the code on the getting server

NOTE: timeout is set to 5 seconds to stop browser from hanging.

$dflURL = 'https://dataflexlink.tech/rest/plugin-info/';

$options = ['http' => [
        'timeout' => 5,
        'method' => 'GET',
        'header' => 'Content-type:application/json'
]];

$context  = stream_context_create($options);

$test = file_get_contents($dflURL,false,$context);

This very same getting server does not have a problem getting data from another server e.g. https://jsonplaceholder.typicode.com/todos/1

This is the getting server which has a problem http://test.tioray.com. This getting server doesn't: http://test.web-dewd-test.co.uk/ You can see both get from https://jsonplaceholder.typicode.com/todos/1 without an issue. You can also click the button at the bottom to see the data come over on ajax from both without a problem.

I'm completely at a loss as to what is causing the problem. The php settings across http://test.web-dewd-test.co.uk/ and http://test.tioray.com seem identical, but only the first works without an issue.

0

There are 0 answers