Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. function guzzleRequest($url, $method, $params = []) {
  2.     $client = new Client();
  3.     $params = $method === 'POST' ? ['body' => json_encode($params)] : ['query' => $params];
  4.     $response = $client->request($method, $url,
  5.         [
  6.             'headers' => [
  7.                 'Content-Type' => 'application/json',
  8.                 'Accept' => 'application/json',
  9.             ],
  10.             'http_errors' => false,
  11.         ] + $params);
  12.     $res = json_decode((string)$response->getBody(), true);
  13.     if ($response->getStatusCode() === 200) {
  14. //        dd($res);
  15.         return $res ?? true;
  16.     } else if ($res['error'] === 404) {
  17.         throw new ApiException($res['error'], 404);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement