A
A
arti_djeims2015-09-14 20:24:55
PHP
arti_djeims, 2015-09-14 20:24:55

Why is the API request not working?

Wrote code:

<?php
$request = 'https://getbible.net/json?p=James3:5';
$response = file_get_contents($request);
$info = array_shift(json_decode($response));

echo($info->verse ." ");
?>

Why does not it work? What needs to be changed to make it work, I need your help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-09-14
Protko @Fesor

Could you at least describe what exactly does not work.
try playing around with the request headers, User agent, referer, etc.

$opts = [
    'http'=> [
        'user_agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0',
    ]
];
$context = stream_context_create($opts);

L
Lulzsec, 2015-09-14
@Lulzsec

At the beginning of the script, add the line
Then there will be no error.

PHP Warning: file_get_contents(https://getbible.net/json?p=James3:5): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question