Virajsinh

curl call

Jul 2nd, 2021 (edited)
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.  
  3.         // echo api_call($input,"city_search","master"); exit;
  4.         $url = ''; # API Link
  5.  
  6.         $post = array('input' => $city);
  7.  
  8.         // $headers = array('content-type:application/json');
  9.  
  10.         $ch = curl_init(); # initialize curl object
  11.         curl_setopt($ch, CURLOPT_URL, $url); # set url
  12.         curl_setopt($ch, CURLOPT_POST, 1); #post data
  13.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post); #post data field
  14.         // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  15.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); # receive server response
  16.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); # do not verify SSL
  17.         $data = curl_exec($ch); # execute curl
  18.         $res = json_decode($data);
  19.         $city_array = array('cities' => $res->data);
  20.         header("Content-type: application/json; charset=utf-8");
  21.         echo json_encode($city_array, JSON_PRETTY_PRINT);
  22.         // return $data;
  23.         // $httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); # http response status code
  24.         // curl_close($ch); # close curl
  25.  
  26. ?>
Add Comment
Please, Sign In to add comment