Advertisement
linuxyamigos

Untitled

Dec 31st, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2.  
  3.     function test(){
  4.         $curl = curl_init();
  5.  
  6.         $obj  = ['email' => "tester3@g.c", "password" => "gogogo"];
  7.         $data = json_encode($obj);
  8.  
  9.         curl_setopt_array($curl, array(
  10.         CURLOPT_URL => "http://simplerest.lan/auth/login",
  11.         CURLOPT_RETURNTRANSFER => true,
  12.         CURLOPT_ENCODING => "",
  13.         CURLOPT_MAXREDIRS => 10,
  14.         CURLOPT_TIMEOUT => 30,
  15.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  16.         CURLOPT_CUSTOMREQUEST => "POST",
  17.         CURLOPT_POSTFIELDS => $data,
  18.         CURLOPT_HTTPHEADER => array(
  19.             "Accept: */*",
  20.             "Accept-Encoding: gzip, deflate",
  21.             "Cache-Control: no-cache",
  22.             "Connection: keep-alive",
  23.             "Content-Length: ". strlen($data),
  24.             "Content-Type: text/plain",
  25.             "Host: simplerest.lan",
  26.             "cache-control: no-cache"
  27.             ),
  28.         ));
  29.  
  30.         $response = curl_exec($curl);
  31.         $err = curl_error($curl);
  32.         $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  33.  
  34.         // Check HTTP status code
  35.         if ($err){
  36.             var_dump($err);
  37.             var_dump('Unexpected HTTP code: '. $http_code);
  38.         }
  39.        
  40.         var_dump(json_decode($response));
  41.         var_dump('HTTP code: '. $http_code);
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement