skip to Main Content

Best regards, I’m using Guzzle 7 with Laravel 8, and I need to pass a path variable, at least that’s how it is called with postman, this my code

$client = new GuzzleHttpClient();  
$response = $client->get('xxxxxxxxxxxxxx', [    'params' => ['dni' => 'xxxxxxx'],    'headers' => ['x-api-key' => 'xxxxxxxxx']   ]);
dd($response);

but it is as if it does not send anything, I would really appreciate if someone knows how to do this query

2

Answers


  1. The guzzle request must look like this:

    $client->get('http://example.com', ['query' => ['param1' => 'value1']]);
    

    This means that you must replace params with query.
    https://docs.guzzlephp.org/en/stable/quickstart.html#query-string-parameters

    Login or Signup to reply.
  2. Instead of using Guzzle, use the native Http facade that is available since Laravel 7.x. Using the facade, you have a dedicated section about what you want here.

    So, your code should be like this:

    Http::get(
        'YOUR_URL',
        [
            'dni' => 'xxxxx',
        ]
    );
    

    And if you want to pass more params, just add index and value, and that’s it!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search