How to perform an HTTP request on the url in yii2?

Hello. How to perform the query and get a response in YII2:
$url = "https://api.content.market.yandex.ru/v1/category.json?geo_id=213";
$headers = array(
 "Host: api.content.market.yandex.ru",
 "Accept: */*",
 "Authorization: <authorizationrules>"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
curl_close($ch);
August 19th 19 at 23:44
2 answers
August 19th 19 at 23:46
Solution
Good afternoon.
It's much easier.
In framework-e has a built-in tool for working with cUrl..
: 2.0 - erna_Hane15 commented on August 19th 19 at 23:52
it is which version? - kamryn_Carter21 commented on August 19th 19 at 23:49
August 19th 19 at 23:48
Wow, thank you!
And not only that.
Is there another yii\httpclient\Client
Use is very simple:
use yii\httpclient\Client;

 $client = new Client();
 $response = $client->createRequest()
->setMethod('post')
->setUrl('http://site.ru/lead/create.json')
->setData($this->getData($model))
->send();

if($response->isOk){
 return $response->data['id'];
}
else{
 return false;
 }
- kamryn_Carter21 commented on August 19th 19 at 23:51

Find more questions by tags PHPYii