【问题标题】:Pagespeed insights - request working locally, but not from AWS serverPagespeed 见解 - 请求在本地工作,但不是来自 AWS 服务器
【发布时间】:2019-12-31 18:51:31
【问题描述】:

我正在尝试使用 google pagespeed 洞察力测试网站。有一个简单的 GET 方法可以使用 google pagespeed insight API 进行测试。我正在尝试自动化该过程,并且我正在使用简单的休息模板。当我在本地运行我的应用程序时,它工作得非常好,在使用 Postman 或只是从 Chrome 浏览器请求时也是如此。问题是当我尝试从我的 AWS 服务器请求数据时。然后它返回一个错误。这是一个示例请求。

https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.infojobs.net

我尝试添加不同的标题等,但问题非常特殊,因为当我尝试向邮递员请求时,没有额外的标题。

{
 "error": {
  "errors": [
   {
    "domain": "lighthouse",
    "reason": "lighthouseError",
    "message": "Lighthouse returned error: ERRORED_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. (Status code: 405)"
   }
  ],
  "code": 500,
  "message": "Lighthouse returned error: ERRORED_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. (Status code: 405)"
 }
}

我知道这不是一个严格的代码问题,但我已经想不出如何解决这个问题以及可能是什么问题。由于网站实际上已经过测试,因此不是网站本身的问题。

【问题讨论】:

    标签: rest pagespeed google-pagespeed pagespeed-insights


    【解决方案1】:

    我通过 curl 使用以下代码进行了尝试,似乎一切正常:

    $pageURL = 'https://www.infojobs.net';
    $APIkey = "YOUR API KEY";
    
    $baseURL = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed";
    $url = $baseURL.'?url='.urlencode($url).'&key='.$APIkey;
    
    $curl = curl_init();
    
    $curl_options = [
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => $url,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_CONNECTTIMEOUT => 60
    ];
    
    curl_setopt_array($curl, $curl_options);
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    
    echo "<pre>";
    print_r(json_decode($response, true));
    echo "<pre>";
    

    请检查一下,让我知道它是否适合您。 我有类似的问题,但我认为这将是服务器配置中的问题。还是你已经修好了?

    【讨论】:

      猜你喜欢
      • 2015-02-14
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 2019-07-26
      • 2021-09-13
      相关资源
      最近更新 更多