• <tfoot id='2cz9X'></tfoot>

    1. <small id='2cz9X'></small><noframes id='2cz9X'>

      <i id='2cz9X'><tr id='2cz9X'><dt id='2cz9X'><q id='2cz9X'><span id='2cz9X'><b id='2cz9X'><form id='2cz9X'><ins id='2cz9X'></ins><ul id='2cz9X'></ul><sub id='2cz9X'></sub></form><legend id='2cz9X'></legend><bdo id='2cz9X'><pre id='2cz9X'><center id='2cz9X'></center></pre></bdo></b><th id='2cz9X'></th></span></q></dt></tr></i><div id='2cz9X'><tfoot id='2cz9X'></tfoot><dl id='2cz9X'><fieldset id='2cz9X'></fieldset></dl></div>
    2. <legend id='2cz9X'><style id='2cz9X'><dir id='2cz9X'><q id='2cz9X'></q></dir></style></legend>
      • <bdo id='2cz9X'></bdo><ul id='2cz9X'></ul>

        带有 POST 数据的 cURL 错误

        时间:2023-10-16

        1. <i id='vnT1g'><tr id='vnT1g'><dt id='vnT1g'><q id='vnT1g'><span id='vnT1g'><b id='vnT1g'><form id='vnT1g'><ins id='vnT1g'></ins><ul id='vnT1g'></ul><sub id='vnT1g'></sub></form><legend id='vnT1g'></legend><bdo id='vnT1g'><pre id='vnT1g'><center id='vnT1g'></center></pre></bdo></b><th id='vnT1g'></th></span></q></dt></tr></i><div id='vnT1g'><tfoot id='vnT1g'></tfoot><dl id='vnT1g'><fieldset id='vnT1g'></fieldset></dl></div>

          <small id='vnT1g'></small><noframes id='vnT1g'>

            <tbody id='vnT1g'></tbody>

                <legend id='vnT1g'><style id='vnT1g'><dir id='vnT1g'><q id='vnT1g'></q></dir></style></legend>
              1. <tfoot id='vnT1g'></tfoot>

                  <bdo id='vnT1g'></bdo><ul id='vnT1g'></ul>
                  本文介绍了带有 POST 数据的 cURL 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想用 Php Curl 从这个 URL 中提取数据:

                  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

                  但我收到以下错误:

                  "{"errorType":"SERVER_ERROR","userErrorMessage":"发生意外的服务器错误.我们对不便表示抱歉.请稍后再试.","errorMessage":"服务器发生异常."}".

                  "{"errorType":"SERVER_ERROR","userErrorMessage":"Unexpected server error occurred. We apologize for the inconvenience. Please try again later.","errorMessage":"Exception occurred in server."}".

                  如何使用 php curl 从该链接中提取数据?

                  How I can extract the data from that link with php curl?

                  这是我的代码

                  $url = 'https://api.traveloka.com/en/v2/flight/search/oneway';              
                  
                  $params = [
                      'context' => [
                          'tvLifetime' => 'eTq6r7InDN+j0vrg5Bujah9yFLWfBGsNGWxzjTBUa/jvVfn8fy/IF40U7OQl0vjmoqMJwuSocopqxISYLLi6YlngzuFViHSWhNHdFgs+49yydWXm5gSjBRwDBFuO0UKHd+B69Ip0Tk1qnKH+oyzW43f2GdS7QOd10yBpqoCOyOk73cVe4oyqCjYUR7X72PoHr14UQNQEUjl1NP5Mcxp+1Gw6RzKF7uV7jMRzmsYbGfGKpYLfsYtxaSx1t35KGWOO605YN9Mj2n5kP5fOD7j2KA9adtfLBtEymWXf6tEt3ug8oBVyzj5c2/pp/hboYilQnDRCih+RwhV5WX7hPTw9IsKapSNtWZ1NX8biH7UyYuhNLgcLK03OS4WNpoO+NphjOPKh09oBpUgrEJ0UqeY+1rfj98lWMAdpMO5rp2E5pvmP7HRuW6CqBwSchPLtVPQAi7ceDGYgYneH+AfodZMd5A==',
                          'tvSession' => '9tCFUug+5pqBk0WdAmwAbThaxD2lAm75JaxFJenJTB2MkEWW7bwVa5FW83NZnCLnlL2TAAijDDIDfD9YbC7NhRws3r5fKxPj62n1bJ+Nck309g3Rkogk+dtxsoMRpFHbkVkEJbYuNFbd9Ckp9iEBGg==',
                          'nonce' => '5eebdd23-2574-4465-afa7-cecc94b8f909'
                      ],
                      'clientInterface' => 'desktop',
                      'data' => [
                          'currency' => 'IDR',
                          'destinationAirportOrArea' => 'DPS',
                          'flightDate' => [
                              'day' => '14',
                              'month' => '10',
                              'year' => '2017'
                          ],
                          'isReschedule' => 'false',
                          'locale' => 'en_ID',
                          'newResult' => 'true',
                          'numSeats' => [
                              'numAdults' => '1',
                              'numChildren' => '0',
                              'numInfants' => '0'
                          ],
                          'seatPublishedClass' => 'ECONOMY',
                          'seqNo' => 'null',
                          'sortFilter' => [
                              'filterAirlines' => [],
                              'filterArrive' => [],
                              'filterDepart' => [],
                              'filterTransit' => [],
                              'selectedDeparture' => '',
                              'sort' => 'null'
                          ],
                          'sourceAirportOrArea' => 'JKTA',
                          'searchId' => 'null',
                          'usePromoFinder' => 'false',
                          'useDateFlow' => 'false'                    
                      ],
                      'fields' => []          
                  ];  
                  
                  $ch = curl_init($url);                                                                      
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);        
                  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
                  curl_setopt($ch, CURLOPT_HEADER, false);
                  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");    
                  curl_setopt($ch, CURLOPT_POST, 1);      
                  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));                                                                                         
                  curl_setopt($ch, CURLOPT_REFERER, "https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY"); 
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                  curl_setopt($ch, CURLOPT_VERBOSE, true); 
                  curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
                      "Host: api.traveloka.com",          
                      "Accept: application/json, text/javascript, */*; q=0.01",
                      "Accept-Language: en-us,en;q=0.5",
                      "X-Requested-With: XMLHttpRequest",         
                      "Connection: keep-alive",
                      "Pragma: no-cache",
                      "Cache-Control: no-cache")                                                                       
                  );                
                  
                  $result = curl_exec($ch);
                  
                  print_r($result);
                  
                  curl_close($ch);    
                  

                  其实我不是在做屏幕爬虫,而是想爬取它的json数据.我在浏览器中打开网络"选项卡并查看 XHR 部分,然后我想从该 XHR 部分获取响应.那么怎么做,我的代码有什么问题?

                  Actually I'm not doing screen crawling, but I want to crawl its json data. I open the "Network" Tab in browser and see the XHR section, and then I want to grab the response from that XHR section. So how to do it and what's wrong with my code?

                  推荐答案

                  根据您使用以下代码提供的 URL,您将获得重定向链接:

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

                  用正确的api替换链接和参数:

                  Replace with the link and parameters with the correct api:

                  此处给出了使用 CURL 的一般格式:

                  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;
                                     }
                  

                  这篇关于带有 POST 数据的 cURL 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 php yii2 在 Chrome 中下载 Excel 文件失败 下一篇:对象配置必须是一个包含“类"的数组.yii2 中的元素与 mongodb

                  相关文章

                  <tfoot id='qGSWy'></tfoot>

                  <small id='qGSWy'></small><noframes id='qGSWy'>

                      <i id='qGSWy'><tr id='qGSWy'><dt id='qGSWy'><q id='qGSWy'><span id='qGSWy'><b id='qGSWy'><form id='qGSWy'><ins id='qGSWy'></ins><ul id='qGSWy'></ul><sub id='qGSWy'></sub></form><legend id='qGSWy'></legend><bdo id='qGSWy'><pre id='qGSWy'><center id='qGSWy'></center></pre></bdo></b><th id='qGSWy'></th></span></q></dt></tr></i><div id='qGSWy'><tfoot id='qGSWy'></tfoot><dl id='qGSWy'><fieldset id='qGSWy'></fieldset></dl></div>
                      <legend id='qGSWy'><style id='qGSWy'><dir id='qGSWy'><q id='qGSWy'></q></dir></style></legend>
                        <bdo id='qGSWy'></bdo><ul id='qGSWy'></ul>