PHP cURL 的请求产生 403

问题描述 投票:0回答:2

我的 PHP cURL 请求出现问题,它显示 403 错误。

在 Postman 和浏览器中,URL 工作正常,Postman 生成了下面的 PHP cURL 代码,但无论如何都显示 403 错误。我猜想在同一个调用中生成了一个 cookie,但是

CURLOPT_COOKIESESSION
不起作用。任何人都可以帮助使用下面的代码来获取 JSON 数据吗?非常感谢。

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://www.britishairways.com/solr/lpbd/lpfdestinations?fq=departure_city:LON+AND+arr_city_name_search:***+AND+trip_type:RT+AND+number_of_nights:7+AND+cabin:M&facet.pivot=arrival_city,is_sales_fare&facet=true',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_COOKIESESSION => true,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
php php-curl
2个回答
0
投票

这个问题你解决了吗,可以帮忙吗,我也遇到了同样的问题


-1
投票
Try this, It's working fine.    



        

$curl = curl_init();
            curl_setopt_array($curl, array(
              CURLOPT_URL => 'https://www.britishairways.com/solr/lpbd/lpfdestinations?fq=departure_city:LON+AND+arr_city_name_search:***+AND+trip_type:RT+AND+number_of_nights:7+AND+cabin:M&facet.pivot=arrival_city,is_sales_fare&facet=true',
              CURLOPT_RETURNTRANSFER => true,
              CURLOPT_ENCODING => '',
              CURLOPT_MAXREDIRS => 10,
              CURLOPT_TIMEOUT => 0,
              CURLOPT_COOKIESESSION => true,
              CURLOPT_FOLLOWLOCATION => true,
              CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
              CURLOPT_CUSTOMREQUEST => 'GET',
            ));
            $response = curl_exec($curl);
            curl_close($curl);
            echo json_encode($response);
© www.soinside.com 2019 - 2024. All rights reserved.