Skip to content

Instantly share code, notes, and snippets.

@crazytonyi
Last active April 19, 2018 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazytonyi/d5ba8033cc308612c92c5dd7cf9fb60c to your computer and use it in GitHub Desktop.
Save crazytonyi/d5ba8033cc308612c92c5dd7cf9fb60c to your computer and use it in GitHub Desktop.
<?php
$client = new \GuzzleHttp\Client();
$request = $client->createRequest('GET', 'https://beta.check-mot.service.gov.uk');
$request->addHeader('x-api-key', 'MY API KEY');
try {
$resp = $client->send($request);
} catch (GuzzleHttp\Exception\ClientException $e) {
$resp = $e->getResponse();
}
echo $resp;
@ZalumsArtis
Copy link

Hi Anthony Im still getting the Type error: Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given, called in /home/web/APIprojecttest/project/vendor/guzzlehttp/guzzle/src/Client.php on line 89, Could it be im missing a package or something?

@crazytonyi
Copy link
Author

What version of Guzzle are you testing this with?

@ZalumsArtis
Copy link

Still the same issue? Could it be due to my pc settings or operating system?

@ZalumsArtis
Copy link

6 I believe

@crazytonyi
Copy link
Author

It's because you are using createRequest, which Guzzle 6 isn't friendly with. This gist works fine in Guzzle 5.3, but has the same error you are seeing when run on Guzzle 6. Check out this gist, which I wrote for Guzzle 6 (and basically is the same as your first example in your SO question, but trimmed down) : https://gist.github.com/crazytonyi/10222135ab7b4d9407d2103130a94cfa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment