Bearer Token in Guzzle HTTP 6.1 not working
<p>I have a problem with my Bearer-Authorization in Guzzle-HTTP.
I use it to test my PHP-REST-API with PHPUnit.</p>

<p>here is my test method:</p>

<pre><code> public function testGetMe()
{
    $client = new Client([
        'base_uri' =&gt; $this-&gt;apiBaseURL
    ]);        
    $data = ['email' =&gt; $email, 'password' =&gt; '12345'];
    $client-&gt;post('register', [
            'form_params' =&gt; $data]
    );
    $responseJson = json_decode($response-&gt;getBody());
    $myToken = $responseJson-&gt;data-&gt;token;

    $response = $client-&gt;request('GET', 'users', [
        'headers' =&gt; [
            'Authorization'      =&gt; 'Bearer '.$myToken
        ],
        'debug' =&gt; true
    ]);
}
</code></pre>

<p>But if I set the token hard coded like this:</p>

<pre><code> public function testGetMe()
{
    $client = new Client([
        'base_uri' =&gt; $this-&gt;apiBaseURL
    ]);        
    $data = ['email' =&gt; $email, 'password' =&gt; '12345'];
    $client-&gt;post('register', [
            'form_params' =&gt; $data]
    );
    $responseJson = json_decode($response-&gt;getBody());
    $myToken = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE0NjQ5NzExMzQsImp0aSI6IjByR3FpOW15Rm1rRGo2TU9sMVhkK3dRU3p1V0pWejM1UEhiU2dTMmg5SEU9IiwiaXNzIjoiQXBwTmFtZSIsIm5iZiI6MTQ2NDk3MTE0NCwiZXhwIjoxNDY0OTczMTQ0LCJzdWIiOiJ0ZXN0QG1haWwuZGUifQ.yA4a_S6ILCeqENm00H712g9uF5g9eSz_BmnaMDdZ2r4p5e1q88g0T09IG2WKCi1oExoBfQ8VTmKeX6ZQv0RydQ;

    $response = $client-&gt;request('GET', 'users', [
        'headers' =&gt; [
            'Authorization'      =&gt; 'Bearer '.$myToken
        ],
        'debug' =&gt; true
    ]);
}
</code></pre>

<p>and also with Postman, it is working.
It's the same token which I receive from my REST-API.</p>

<p>Do you have any ideas what's wrong?</p>