delucaspinto

[ PHP ] CURL EXAMPLE

Oct 1st, 2019
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. // CURL EXAMPLE
  2.  
  3.     try {
  4.  
  5.         $url = "http://localhost/webservices/sac/faturas-site/$cpfcnpj";
  6.         $curl = curl_init();
  7.         curl_setopt($curl, CURLOPT_URL, $url);
  8.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  9.         $output = curl_exec($curl);
  10.         $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  11.         curl_close($curl);
  12.  
  13.         if ($http_code == 200)
  14.         {
  15.             $response = json_decode($output);
  16.             return view('processa-boleto-cpf', compact( 'response', 'cpfcnpj', 'tipo', 'http_code'));
  17.  
  18.         } else {
  19.  
  20.             throw new Aviso('Não foi possível encontrar alguma informação');
  21.         }
  22.  
  23.  
  24.     } catch (Exception $e) {
  25.  
  26.         throw new Aviso('Não foi possível encontrar alguma informação.');
  27.  
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment