-1

I get file_get_contents(https://koinex.in/api/ticker):failed to open stream: HTTP request failed! error

what am I doing wrong?

Srini V
  • 11,045
  • 14
  • 66
  • 89
Hashh
  • 1
  • 6

1 Answers1

0

You may try something like this:

$context = stream_context_create([ 
    'http'=> [ 
        'method'=> 'GET', 
        'user_agent'=> $_SERVER['HTTP_USER_AGENT'] 
    ]
]); 

$data = json_decode(
    file_get_contents('https://koinex.in/api/ticker', false, $context)
);

The following https://koinex.in/api/ticker works from browser so it seems that all you need to set a user_agent to fool the server that the request is being made by a real user using a browser. Also read about stream_context_create.

The Alpha
  • 143,660
  • 29
  • 287
  • 307