title: Guzzle POST request to JWT API get Unauthorized while Postman is working
body: <p>Guzzle POST request to JWT API get Unauthorized while Postman is working.
  Here is the code:</p>
  
  <pre><code>public function __construct()
  {
      $this-&gt;client = new Client();
      $this-&gt;connect();
  }
  
  public function connect()
  {
      $loginResult = $this-&gt;client-&gt;request('POST', config('api.base_uri') .'/auth/login', [
          'form_params' =&gt; [
              'email' =&gt; config('api.login'),
              'password' =&gt; config('api.password'),
          ]
      ]);
  
      dd(json_decode($loginResult-&gt;getBody()));
  
  }
  </code></pre>
  
  <p>I got 401 Unauthorized while running this code. Credentials are passed correctly.
  Meanwhile in Postman it is working perfectly:
  <a href="https://i.stack.imgur.com/CfA3Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CfA3Q.png" alt="While in Postman it is working perfectly"></a></p>
  
  <p>Kindly advise me what I'm doing wrong.
  Thanks!</p>
  
  <p><strong>UPDATE</strong>
  Following is controller and function this request is hitting in API side:</p>
  
  <pre><code>class AuthController extends Controller
  {
      public function __construct()
      {
          $this-&gt;middleware('auth:api', ['except' =&gt; ['login']]);
      }
  
      public function login(Request $request)
      {
          $credentials = $request-&gt;only(['email', 'password']);
  
          if (!$token = auth('api')-&gt;attempt($credentials)) {
              return response()-&gt;json(['error' =&gt; 'Unauthorized '.$credentials['email']], 401);
          }
  
          return $this-&gt;respondWithToken($token);
      }
  ...
  </code></pre>
  
  <p>User does exist as it is working in Postman</p>
  
  <p><strong>UPDATE 2</strong>
  I have simplified code to find that is wrong to:</p>
  
  <pre><code>Route::get('/guzzle', function () {
      $client = new Client([
          'headers' =&gt; [
              'Accept' =&gt; 'application/json'
          ]]);
  
      $loginResult =
          $client-&gt;request('POST', config('pics.base_uri') .'/auth/login', [
              'form_params' =&gt; [
                  'email' =&gt; '****@****.com',
                  'password' =&gt; '*****',
              ]
          ]);
  
      dd(json_decode($loginResult-&gt;getBody()));
  });
  </code></pre>
  
  <p>And it does not work - got same error</p>