Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Guzzle\Http\Client;
- use Guzzle\Plugin\Log\LogPlugin;
- use /** @noinspection PhpUndefinedNamespaceInspection */
- Guzzle\Log\MessageFormatter;
- use /** @noinspection PhpUndefinedNamespaceInspection */
- Guzzle\Http\Exception\ClientErrorResponseException;
- use /** @noinspection PhpUndefinedNamespaceInspection */
- Guzzle\Http\Exception\RequestException;
- use Guzzle\Http\Message\Response;
- class HttpClient
- {
- public $http;
- public $request;
- /**
- * HttpClient
- */
- public function __construct()
- {
- $this->init();
- }
- /**
- * Инициилизация httpClient
- */
- public function init()
- {
- $this->http = new Client();
- }
- /**
- * метод post
- * $uri - url
- */
- public function post($uri = null, $headers = null, $postBody = null, array $options)
- {
- $this->request = $this->http->post($uri, $headers, $postBody, array('exceptions' => false))->send();
- return $this;
- }
- /**
- * метод get
- */
- public function get($uri = null, $headers = null, array $options)
- {
- $this->request = $this->http->get($uri, $headers, array('exceptions' => false))->send();
- return $this;
- }
- /**
- * получение заголовков ответа
- */
- public function getHeader()
- {
- if ($this->request instanceof Response) {
- return $this->request->getRawHeaders();
- } else throw new Exception("Ошибка: запрос не был отправлен");
- }
- /**
- * получение тела ответа
- */
- public function getBody()
- {
- if ($this->request instanceof Response) {
- return $this->request->getBody();
- } else throw new Exception("Ошибка: запрос не был отправлен");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment