Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ESService
- {
- public $request;
- public $method;
- public $url;
- public $response;
- public function __construct()
- {
- $this->url = Yii::app()->params['service'].'/webresources/uin/generate';
- }
- // Возвращает тип запроса
- public function getRequestType()
- {
- $this->method = Yii::app()->request->getRequestType();
- return $this->method;
- }
- //Возвращает тело запроса
- public function getRawBody()
- {
- $this->request = Yii::app()->request->getRawBody();
- return $this->request;
- }
- //Получение ответа от внешнего сервиса
- public function getResponse($method, $request)
- {
- switch ($method) {
- case 'GET':
- $response = Yii::app()->httpClient->get($this->url,
- array('content-type' => 'application/json'), array('exceptions' => false))->getBody();
- break;
- case 'POST':
- $response = Yii::app()->httpClient->post($this->url,
- array('content-type' => 'application/json'), $request, array('exceptions' => false))->getBody();
- break;
- }
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment