D
D
Denis99992018-08-20 16:17:50
PHP
Denis9999, 2018-08-20 16:17:50

Error when requesting PHP api?

The problem is that when you do concatenation in this line, the code stops working:

$url = 'https://api.coindesk.com/v1/bpi/historical/close.json?start='.$today_minus_god .'&end=2018-08-20';

The following response is returned:
Warning: file_get_contents(https://api.coindesk.com/v1/bpi/historical/close.json?start=2017-20-08&end=2018-08-20): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp\htdocs\wp2.com\wp-content\themes\twentyfifteen\page-15.php on line 40

The code is like this:
$today = date("Y-d-m");
$minus_god_microtime = getdate(mktime(0, 0, 0, date('m'), date('d'), date('Y') - 1 ));
$today_minus_god = date("Y-d-m", $minus_god_microtime[0]);
$url = 'https://api.coindesk.com/v1/bpi/historical/close.json?start=2017-08-20&end=2018-08-20';
$json = file_get_contents($url);
$json = json_decode($json, true);
print_r($json);

I rechecked $url after concatenation, everything is correct there. What could be the problem here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-08-20
@Denis9999

Have you tried opening it in a browser? It even writes an error there.
Does anything bother you about the date?
?start=2017-20-08&end=2018-08-20

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question