Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CJLees01's avatar

Guzzle dropping slashes?

I'm trying to make a Guzzle (6.3.0) call from my Laravel 5.4 app, and for some inexplicable reason it keeps dropping slashes from my URL and I just don't understand why... Anybody seen this before?

Here's my Controller:

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;

    public function makeCall() 
    {
    $client  = new Client();
    $headers = ['api-key'    => 'xxx', 'api-secret'   => 'yyy'];

        $response = $client->get("http://testurl.dev/spec/network/status/4GvXeqC0/", ['headers' => $headers]);
    ...
    }

This call fails with the following 404 error:

GuzzleHttp\Exception\ClientException: Client error: `GET http://testurl.dev/spec/network/status4GvXeqC0` resulted in a `404 Not Found` response:
...

The reason appears to be that it is dropping the slash between the last two segments (ie status4GvXeqC0 and not status/4GvXeqC0). Anybody know why?

0 likes
1 reply
CJLees01's avatar

After some more random-trial-and-error, the plot thickens still further, as adding headers seems to further break things.

This code at least hits the correct URL:

$client  = new Client(['base_uri' => 'http://testurl.dev/spec/network/status']);
$response = $client->request('GET', 'status/4GvXeqC0'); 

But it (predictably) fails because I've dropped my header data:

[2017-07-04 20:52:22] production.ERROR: GuzzleHttp\Exception\ClientException: Client error: `GET http://testurl.dev/spec/network/status/4GvXeqC0` resulted in a `401 Unauthorized` response: {"error":"API key or secret missing."}

If however I add headers back in to my Guzzle request, I go back to bad URL again...

$client  = new Client(['base_uri' => 'http://testurl.dev/spec/network/status']);
$headers = ['api-key' => 'xxx', 'api-secret' => 'yyy'];
$response = $client->request('GET', 'status/4GvXeqC0', ['headers'  => $headers]);
GuzzleHttp\Exception\ClientException: Client error: `GET http://testurl.dev/spec/network/status4GvXeqC0` resulted in a `404 Not Found` response:

Guzzle is so widely used, I can't believe that this is a bug... I've got to be missing something obvious :-|

Please or to participate in this conversation.