You must load it in your controller methods, where it is necessary or, if desired, autoload. I use the first: First: use it using the composer in the application folder:
composer require guzzlehttp/guzzle:~6.0
Second: let CI autoload composer (application / config / config.php)
$config['composer_autoload'] = TRUE;
Then in your controller
public function guzzler_get($url, $uri) { $client = new GuzzleHttp\Client(['base_uri' => $url]); $response = $client->get($uri); // print_r($response); // print out response // print out headers: // foreach ($response->getHeaders() as $name => $values) { // echo $name . ': ' . implode(', ', $values) . "\r\n"; // } return $response; }
Using:
$your_var = $this->guzzler_get('http://httpbin.org', '/html');
Now you have the answer in the variable $your_var . Otherwise check the documentation. Otherwise, use a "friendly" method / library for your HTTP requests, such as CodeIgniter-cURL or Requests
wiZZmnma
source share