Error on cURL with POST data

前端 未结 2 1788
自闭症患者
自闭症患者 2021-01-26 08:21

I want to extract data from this URL with Php Curl:

https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY

2条回答
  •  清酒与你
    2021-01-26 08:39

    As per the URL you have given using the below code, you would get nothing rather the redirection link:

    Replace with the link and parameters with the correct api:

    General format of using CURL is given here:

                $ch = curl_init();
    
               $params = urldecode('{"ap":"' . 'JKTA.DPS' . '","dt":"' . '14-10-2017.NA' . '","ps":"' . '1.0.0'. '","sc":"' . 'ECONOMY'. '"}');
    
    
    
                $url = 'https://www.traveloka.com/en/flight/fullsearch?JsonData=' . $params;
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                // curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
    
                curl_setopt($ch, CURLOPT_HEADER, 0);
    
                // Should cURL return or print out the data? (true = return, false = print)
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
                // Timeout in seconds
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    
                // Download the given URL, and return output
                $output = curl_exec($ch);
    
                // Close the cURL resource, and free system resources
                curl_close($ch);
    
                if (!empty($output)) {
                    $x = json_decode($output, true);
                            var_dump($x);   
                       }else{
                          return FALSE;
                       }
    

提交回复
热议问题