Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. public static function doRequest2($data, $service = null, $type = "POST") {
  2.         self::logDataRow('Making request');
  3.         if ($service) {
  4.                 $data_string = json_encode($data);
  5.                 $referer = urlencode('http://pps.vptest.ee/');
  6.                 $url = 'https://dev.pakipoint.ee/'.$service."/";
  7.                 $token = 'f27343bb19659f731e0701041822cd7ba5e257a9';
  8.                 self::logDataRow('Url for request');
  9.                 self::logDataRow($url);
  10.                 self::logDataRow('Request data');
  11.                 self::logData($data_string);
  12.                 self::logDataRow('Token');
  13.                 self::logData($token);
  14.                 $ch = curl_init($url);
  15.                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
  16.                 curl_setopt($ch, CURLOPT_POST, true);
  17.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  18.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  19.                 curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_REFERER']);
  20.                 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  21.                     'Accept: application/json',
  22.                     'Content-Type: application/json',
  23.                     'Content-Length: ' . strlen($data_string),
  24.                     'Authorization: Token '.$token)
  25.                 );
  26.                 $response = curl_exec($ch);
  27.                 self::logDataRow('Response');
  28.                 self::logData($response);
  29.                 $http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  30.                 curl_close($ch);
  31.                 if ($http_status_code >= 200 && $http_status_code < 300) {
  32.                     $result = json_decode($response, true);
  33.                     return $result;
  34.                 }
  35.                 else if ($http_status_code >= 400 && $http_status_code < 500) {
  36.                     $validation_errors = json_decode($response, true);
  37.                 }
  38.                 else {
  39.                 }
  40.         }
  41.         return false;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement