Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function doRequest2($data, $service = null, $type = "POST") {
- self::logDataRow('Making request');
- if ($service) {
- $data_string = json_encode($data);
- $referer = urlencode('http://pps.vptest.ee/');
- $url = 'https://dev.pakipoint.ee/'.$service."/";
- $token = 'f27343bb19659f731e0701041822cd7ba5e257a9';
- self::logDataRow('Url for request');
- self::logDataRow($url);
- self::logDataRow('Request data');
- self::logData($data_string);
- self::logDataRow('Token');
- self::logData($token);
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_REFERER']);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Accept: application/json',
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data_string),
- 'Authorization: Token '.$token)
- );
- $response = curl_exec($ch);
- self::logDataRow('Response');
- self::logData($response);
- $http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- if ($http_status_code >= 200 && $http_status_code < 300) {
- $result = json_decode($response, true);
- return $result;
- }
- else if ($http_status_code >= 400 && $http_status_code < 500) {
- $validation_errors = json_decode($response, true);
- }
- else {
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement