2016-06-30 48 views
0

我有得到一個URL響應的響應捲曲,它的格式是這樣的:使用捲曲和PHP一個響應多個狀態

{"status": "OK", "tracking_id": "363070a8-53b6-49da-a7e9-6a289a3501f2"}

有時捲曲執行不止一次和我收到1當我只執行一次時,可以給5個不同的響應。

我執行的URL看起來是這樣的:

$request = "https://precise-line.com/2/delivery/request?"; 
       $request.= "api_key=".$api_key."&"; 
       $request.= "user_id=".$user_id."&"; 
       $request.= "delivery_type=".$delivery_type."&"; 
       $request.= "route=E.+Pallares+y+Portillo&"; 
       $request.= "street_number=110&"; 
       $request.= "neighborhood=San+Lucas&"; 
       $request.= "locality=Distrito+Federal&"; 
       $request.= "administrative_area_level_1=Distrito+Federal&"; 
       $request.= "postal_code=04030&"; 
       $request.= "country=Mexico&"; 
       $request.= "latlng=".$latlng."&"; 
       $request.= "destination-route=".$destination_route."&"; 
       $request.= "destination-street_number=&"; 
       $request.= "destination-neighborhood=&"; 
       $request.= "destination-locality=".$destination_locality."&"; 
       $request.= "destination-administrative_area_level=".$destination_administrative_area_level."&"; 
       $request.= "destination-postal_code=".$destination_postal_code."&"; 
       $request.= "destination-country=Mexico&"; 
       $request.= "destination-latlng=".$d_latlng."&"; 
       $request.= "customer_email=".$customer_email."&"; 
       $request.= "customer_phone=".$customer_phone."&"; 
       $request.= "notification_email=&"; 
       $request.= "notes=".$notes."&"; 
       $request.= "dispatch=True"; 

error_log("Request"); 
      error_log(print_r($request, true)); 

      $ch_request=curl_init(); 
      $curl = curl_init(); 
      curl_setopt($curl, CURLOPT_URL, $request); 
      curl_setopt($curl, CURLOPT_SSLVERSION, 1); 
      //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
      curl_setopt($curl, CURLOPT_HEADER, FALSE); 
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 

      $response = curl_exec($curl); 
      curl_close ($curl); 

      error_log("Response"); 
      error_log(print_r($response, TRUE)); 

如何防止捲曲從執行不止一次?

+1

不應該運行一次以上,除非你多次調用它 –

回答

0

爲什麼你有$ ch_request和$ curl?我不知道這是否有所作爲,但您應該使用$ ch_request刪除該行。否則,正如Dagon所說的,如果你一次給它打電話,你就不應該有多個迴應。

+0

是的我有這個錯誤,我複製其他代碼,但也是這樣做...所以不是cURL,它使多個響應也許可能是其他的東西? – victor