I have my config/mail 'driver' set to mandrill, host, port, etc. including in services.php mandrill secret set.
Sending Mail works fine locally, but on the live server I get:
Class 'GuzzleHttp\Client' not found
I have tried "guzzlehttp/guzzle": "~5.3|~6.0", and then back to "guzzlehttp/guzzle": "~4.0", no luck. I have done composer update, and dump-autoload still no luck on my live server. Been through every other associated Stackoverflow question and still can't resolve.
Please follow these simple steps:
First: Place this on top of your class
use Guzzlehttp\Client;
Second: Inside your function, instead of using
$client = new Client();
use
$client = new \GuzzleHttp\Client();
reference:
http://docs.guzzlephp.org/en/latest/quickstart.html
try composer require guzzlehttp/guzzle without specifying the version. Worked for me
Error ? the library GuzzleHttp (which is a Simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data ) is either missing or mis-configured.
Solution : run the following command on your terminal(root folder):
composer require guzzlehttp/guzzle:^6.5
Related
I am currently using PHP CURL but somehow it is not working for basicAUTH in my case. I want to use guzzel HTTP client in simple PHP project (not a Laravel project). Every solution on the internet I found is setting up in laravel and installing it via composer.
$client = new \GuzzleHttp\Client();
$response = $client->post($service_url, [
'auth' => [
$username,
$admin_password
]
]);
or if guzzel do not works with simple PHP, Suggest other client which can work with simple PHP for basic Auth. Thanks
First of all you need to navigate to your main forder you will be working in, which reside inside htdocs as usual and then insall GuzzleHttpClient by using composer tool
(Recommended: 2+ version)
composer require guzzlehttp/guzzle
It will download and install dependencies such as:
symfony/deprecation-contracts
psr/http-message
psr/http-client
guzzlehttp/promises
ralouphie/getallheaders, etc.
After getting it fully installed; try simple example to see if it really works
<?php
// First of all require autoload from vendor dir;
require_once "vendor/autoload.php";
use GuzzleHttp\Client;
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'https://reqres.in',
]);
// The response to get
$res = $client->request('GET', '/api/users', [
'query' => ['page' => '2', ]
]);
$body = $res->getBody();
$array_body = json_decode($body);
print_r($array_body);
?>
Check the result in the browser
Composer has nothing to do with Laravel or Guzzle, is "just" a package manager.
You can use - and I suggest to do so - composer in your project even if you're not using a framework.
Said that, once you have Guzzle source code (via composer or downloading directly the code; I would not reccommend the latter) you can just use it everywhere.
By the way I would suggest to use composer for two (main) reasons:
You can keep under control dependencies (like Guzzle) in order to update/downgrade them easily. Also composer will track possible conflicts with other dependencies (that for instance can't work together under some circumstances)
Composer has its own psr-4 autoloader
So yes, you can use Guzzle also without a framework and without composer, there's nothing preventing you to do so.
Recently i am working on a package for Laravel.
I am at beginner level on Laravel Package Development.
I need to use Guzzle Client for an API request from this package.
If i use use GuzzleHttp\Client; in my controller, it's showing class not found. (I know why. because it's outside of app folder and not autoloaded for this path)
Now, how can i use guzzle inside of my custom package controller.
Here what i wanting:
This is my controller method:
public function packageList($vendor, $type)
{
$client = new Client();
$result = $client->get('https://packagist.org/packages/list.json?vendor='.$vendor.'&type='.$type, [
'form_params' => [
'sample-form-data' => 'value'
]
]);
dd($result);
}
I attached classes of Guzzle
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
Getting Exception:
Class 'GuzzleHttp\Client' not found
Found this answer on stack with the same question
Open up your terminal at the root of your project and enter
composer require guzzlehttp/guzzle
It worked for the mailgun API. For some reason, the suggested method at the laravel's mail doc. You may install this package to your project by adding the following line to your composer.json file
"guzzlehttp/guzzle": "~5.3|~6.0"
doesn't make the composer download the Guzzle source codes. By the way, I didn't find out what | means in determining the version. This command just downloads the PSR code.
In this moment, the solution may work. However, be aware of compatibility issues. Because the command would install the latest stable version, not the suitable one.
answer by: shampoo
if this doesnt help, try reading the docs : http://docs.guzzlephp.org/en/stable/quickstart.html
I try to make an API Request to the Github API just for testing. I installed the latest Guzzle Version ( "guzzle/guzzle": "^3.9" ) on my Laravel 5.1 APP.
In my routes.php i have the following Code:
Route::get('guzzle/{username}', function($username) {
$client = new Client([
'base_uri' => 'https://api.github.com/users/',
]);
$response = $client->get("/users/$username");
dd($response);
});
If i now visit the URL domain.dev/github/kayyyy i get the Error cURL error 6: Could not resolve host: users.
Why am i getting this Error?
If i visit https://api.github.com/users/kayyyy i can see the json output.
I am also using Homestead / Vagrant is this maybe a Problem that the host cant be resolved?
EDIT
If i try this without the base_uri it works.
Route::get('guzzle/{username}', function($username) {
$client = new GuzzleHttp\Client();
$response = $client->get("https://api.github.com/users/$username");
dd($response);
});
Why are you calling $client->get->()->send()? In particular, why are you chaining the send() method at the end? The documentation does not append the send() method when demonstrating what seems to be the same action:
http://guzzle.readthedocs.org/en/latest/quickstart.html#creating-a-client
Also, did you consider the implications of this statement on the above-cited manual page?
When a relative URI is provided to a client, the client will combine the base URI with the relative URI using the rules described in RFC 3986, section 2.
Actually a variable interpolation is not possible within single quotes. This means that you currently are calling users/$username and the $username variable gets not replaced with its value.
In order to get it, you should use it in one of the following ways:
$response = $client->get("users/$username")->send();
$response = $client->get('users/' . $username)->send();
I personally prefer the second one as it is assumed to be faster.
Okay i solved it, stupid mistake by me.
I used new Client.
And it should be of course new GuzzleHttp\Client
As it is just for testing in my routes.php i did not the Namespace
Thanks for your help everybody.
Thanks to Paratron
https://github.com/googleapis/google-api-php-client/issues/1184#issuecomment-355295789
In my case, on cakephp 3.8 & docker 19.03.5, I was facing curl error due to some network issue. I restarted my cake-server docker container, & it worked like a charm.
Your Laravel installer is very out of date. The only way to get the latest version is to remove and install again:
composer global remove laravel/installer
composer global require laravel/installer
I've implemented a mail delivery service using SparkPost for a website. The code looks like this:
require '/vendor/autoload.php';
use SparkPost\SparkPost; use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
$httpAdapter = new Guzzle6HttpAdapter(new Client());
$sparky = new SparkPost($httpAdapter, ['key'=>'...']);
[...]
[...]
$results = $sparky->transmission->send($mailarray);
It works just fine locally on WampServer, however when I deploy it to Azure it does not. I don't have access to Azure logs, but I managed to narrow down the problem to one line:
$sparky = new SparkPost($httpAdapter, ['key'=>'...']);
I simply get a 500 error without any other explanation. The weird thing is when I wrap it around a try/catch, I still don't get anything other than a blank screen and a 500 on the console. I suspect it has to do something with /autoload.php not being able to load something.
Any thoughts?
According the requirement of SparkPost lib on Github repo at https://github.com/SparkPost/php-sparkpost/blob/master/composer.json#L18, it need PHP version higher than 5.5. So you can modify the PHP version of your Azure Web Apps, please refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/#how-to-change-the-built-in-php-version for detail steps.
I try to make an API Request to the Github API just for testing. I installed the latest Guzzle Version ( "guzzle/guzzle": "^3.9" ) on my Laravel 5.1 APP.
In my routes.php i have the following Code:
Route::get('guzzle/{username}', function($username) {
$client = new Client([
'base_uri' => 'https://api.github.com/users/',
]);
$response = $client->get("/users/$username");
dd($response);
});
If i now visit the URL domain.dev/github/kayyyy i get the Error cURL error 6: Could not resolve host: users.
Why am i getting this Error?
If i visit https://api.github.com/users/kayyyy i can see the json output.
I am also using Homestead / Vagrant is this maybe a Problem that the host cant be resolved?
EDIT
If i try this without the base_uri it works.
Route::get('guzzle/{username}', function($username) {
$client = new GuzzleHttp\Client();
$response = $client->get("https://api.github.com/users/$username");
dd($response);
});
Why are you calling $client->get->()->send()? In particular, why are you chaining the send() method at the end? The documentation does not append the send() method when demonstrating what seems to be the same action:
http://guzzle.readthedocs.org/en/latest/quickstart.html#creating-a-client
Also, did you consider the implications of this statement on the above-cited manual page?
When a relative URI is provided to a client, the client will combine the base URI with the relative URI using the rules described in RFC 3986, section 2.
Actually a variable interpolation is not possible within single quotes. This means that you currently are calling users/$username and the $username variable gets not replaced with its value.
In order to get it, you should use it in one of the following ways:
$response = $client->get("users/$username")->send();
$response = $client->get('users/' . $username)->send();
I personally prefer the second one as it is assumed to be faster.
Okay i solved it, stupid mistake by me.
I used new Client.
And it should be of course new GuzzleHttp\Client
As it is just for testing in my routes.php i did not the Namespace
Thanks for your help everybody.
Thanks to Paratron
https://github.com/googleapis/google-api-php-client/issues/1184#issuecomment-355295789
In my case, on cakephp 3.8 & docker 19.03.5, I was facing curl error due to some network issue. I restarted my cake-server docker container, & it worked like a charm.
Your Laravel installer is very out of date. The only way to get the latest version is to remove and install again:
composer global remove laravel/installer
composer global require laravel/installer