Axxxxxx

sample.php

Jun 30th, 2021 (edited)
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Пример запроса.
  4.  */
  5. require_once $_SERVER['DOCUMENT_ROOT'].'/kint.php';
  6. function apiRequest($token, $data)
  7. {
  8.     header('Content-Type: application/json');
  9.     $ch = curl_init('http://tau.mdm-complect.ru/api/');
  10.     // $headers[] = "Content-Type: application/json";
  11.     // $headers[] = "Accept: application/json";
  12.     $headers[] = "Authorization: Bearer $token";
  13.     // $headers[] = "Accept-Language: en";
  14.     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  15.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  16.     curl_setopt($ch, CURLOPT_POST, 1);
  17.     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  18.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  19.     $result = curl_exec($ch);
  20.     curl_close($ch);
  21.  
  22.     return $result;
  23. }
  24.  
  25. $token = '111ea2450228a5d655e3a8c2f9a5aedc30b591df';
  26. $data = [
  27.     'type' => 'get',
  28.     'form_id' => 2,
  29.     'limit' => 3,
  30.     // 'from' => '02.04.2021',
  31.     // 'to' => '02.04.2021',
  32. ];
  33. $request = apiRequest($token, $data); // Send or retrieve data
  34.  
  35. echo $request;
  36. die;
  37.  
Add Comment
Please, Sign In to add comment