Почему мой веб-сервер apache2 не отвечает на запросы curl - PullRequest
0 голосов
/ 22 сентября 2019

Я пытался использовать Google Pagespeed Insights API в PHP, используя php-curl, и отправлял запросы на веб-страницу .html, которую я создал на своем локальном сервере.Предположим, мой IP-адрес 123.456.78.90;так вот мой сценарий:

$url = "http://123.456.78.90/webproject/test/some.html";
//$url = "https://developers.google.com";

$curl_init = curl_init("https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=$url&screenshot=true&key=***********");
curl_setopt($curl_init, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_init, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
$response = curl_exec($curl_init);
curl_close($curl_init);
$googlepsdata = json_decode($response, true);
echo "response: "; print_r($googlepsdata); echo "<br><br><br>";//check 

Вот ответ:

response: Array ( [error] => Array ( [errors] => Array ( [0] => Array ( [domain] => lighthouse [reason] => lighthouseError [message] => Lighthouse returned error: FAILED_DOCUMENT_REQUEST. Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Details: net::ERR_CONNECTION_FAILED) ) ) [code] => 500 [message] => Lighthouse returned error: FAILED_DOCUMENT_REQUEST. Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Details: net::ERR_CONNECTION_FAILED) ) )

ЧТО Я ПОПРОБОВАЛ:

  1. Но когда я изменяю значение $url на https://developers.google.com, я получаю правильный ответ JSON.
  2. Поэтому я попытался использовать утилиту curl в Ubuntu с терминала и выполнил curl https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url={http://123.456.78.90/webproject/test/some.html}&screenshot=true&key=**********, но все равно получил
        sn@ubuntu:~$ curl https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url={http://123.456.78.90/webproject/test/some.html}&screenshot=true&key=AIzaSyCvLhgU6dByk_eDRV3FCg4g66oVONau2-8
        [1] 3987
        [2] 3988
        sn@ubuntu:~$ {
         "error": {
          "errors": [
           {
            "domain": "lighthouse",
            "reason": "lighthouseError",
            "message": "Lighthouse returned error: FAILED_DOCUMENT_REQUEST.
    Lighthouse was unable to reliably load the
    page you requested. Make sure you are testing the correct URL and
    that the server is properly responding to all requests. (Details:
    net::ERR_CONNECTION_FAILED)"
           }
          ],
          "code": 500,
          "message": "Lighthouse returned error: FAILED_DOCUMENT_REQUEST.
    Lighthouse was unable to reliably load the
    page you requested. Make sure you are testing the correct URL and
    that the server is properly responding to all requests. (Details:
    net::ERR_CONNECTION_FAILED)"
         }
        }

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...