首页 文章

从uri获取json的php / guzzle

提问于
浏览
0

我正在做一个工匠命令,在这个网页上获取json:https://www.arera.it/it/atti-18.json

我正在使用php / guzzle库:

$client = new \GuzzleHttp\Client();
$crawler = $client->request('GET', 'https://www.arera.it/it/atti-18.json');
echo $res->getBody();

但我在输出控制台中收到此信息:

<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 5887289226846801693</body></html>

而不是json . 有人可以帮帮我吗?我正在使用laravel 5.4和最新版本的guzzle .

2 回答

  • 0

    好的,我已经解决了我的问题 . 在我的客户端请求中,我添加了头文件数组,如guzzle文档http://docs.guzzlephp.org/en/stable/request-options.html#headers . 所以我的客户请求是:

    $res = $client->request('GET', 'https://www.arera.it/it/atti-18.json',[
            'headers' => [
                'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36',
                'accept' => 'image/webp,image/apng,image/*,*/*;q=0.8'
                ],
            'debug' => 'true',
        ]);
    

    也许它可以帮助其他民族 . 谢谢你的回复 .

  • 0

    这样的消息可以由保护服务器免受滥用的过滤器生成 . 此类禁令通常会在一天后到期,因此您可以稍后再试 .

相关问题