title: Guzzle error "Call to a member function getStatusCode() on null" when curl and Postman are perfectly fine
body: <p>I'm setting up Guzzle as my Laravel 6's HTTP Client in my project. It was perfectly working and giving responses on every API hit. But suddenly it returns &quot;Call to a member function getStatusCode() on null&quot; error.</p>
  <p>I've tried using Postman and curl to hit the API, and they return the right response when Guzzle not.</p>
  <p>Instead of returning response, the print_r for RequestException response's return null.</p>
  <p>I've <strong>tried to debug</strong> the REST API to test where the request go when hitting it using Guzzle, and the <strong>request didn't even hit to the destination function</strong>.</p>
  <p>Here's my Guzzle code:</p>
  <pre class="lang-php prettyprint-override"><code>class ApiCallback
  {
      public static function request($method, $uri, $params = [], $useAccessToken = true){
          $client = new \GuzzleHttp\Client();
          $response = null;
  
          $jsonObj = null;
          try{
              if($useAccessToken){
                  $response = $client-&gt;request(
                      strtoupper($method),
                      $uri,
                      [
                          &quot;headers&quot; =&gt;[
                              'Accept' =&gt; '*/*',
                              &quot;Authorization&quot; =&gt; &quot;Bearer &quot;.Session::get('access_token'),
                              'Content-Type' =&gt; 'application/json',
                              'User-Agent' =&gt; 'saranaku-'.Session::get('id'),
                              'Content-Length' =&gt; '0',
                              'Accept-Encoding' =&gt; 'gzip, deflate, br',
                              'Connection' =&gt; 'keep-alive'
                          ]
                          ,
                          &quot;body&quot; =&gt; \json_encode(
                              $params
                          )
                      ]
                  );
              }else{
                  $response = $client-&gt;request(
                      strtoupper($method),
                      $uri,
                      [
                          &quot;headers&quot; =&gt;[
                              'Accept' =&gt; '*/*',
                              'Content-Type' =&gt; 'application/json',
                              'User-Agent' =&gt; &quot;saranaku-guest&quot;,
                              'Content-Length' =&gt; '0',
                              'Accept-Encoding' =&gt; 'gzip, deflate, br',
                              'Connection' =&gt; 'keep-alive'
                          ]
                          ,
                          &quot;body&quot; =&gt; \json_encode(
                              $params
                          )
                      ]
                  );
              }
              $jsonObj = json_decode((string) $response-&gt;getBody());
              return new BaseResponse(
                  $jsonObj-&gt;status ?? false,
                  $jsonObj-&gt;code ?? null,
                  $jsonObj-&gt;message ?? null ,
                  $jsonObj-&gt;data ?? null
              );
          }catch(RequestException $e){
  //            echo Psr7\str($e-&gt;getRequest());
  //            echo Psr7\str($e-&gt;getResponse());
              $jsonObj = $e-&gt;getResponse();
              print_r($e-&gt;getResponse());
          }
          return new BaseResponse(
              $jsonObj-&gt;status ?? false,
              $jsonObj-&gt;getStatusCode() ?? null,
              $jsonObj-&gt;getReasonPhrase() ?? null ,
              $jsonObj-&gt;data ?? null
          );
      }
  
      public static function requestWithoutAccessToken($method, $url, $params = []){
          return ApiCallback::request($method, $url, $params, false);
      }
  }
  
  final class BaseResponse
  {
      public $status;
      public $code;
      public $message;
      public $data;
  
      public function __construct($status,$code,$message = &quot;&quot;,$data = [])
      {
          $this-&gt;status = $status;
          $this-&gt;code = $code;
          $this-&gt;message = $message;
          $this-&gt;data = $data;
      }
  }
  
  </code></pre>
  <p>Additional information:</p>
  <ol>
  <li>The REST API is running in localhost with endpoint: /v1/login</li>
  <li>The HTTP method is POST</li>
  <li>The REST API is using Java Spring Boot v1.5.6</li>
  <li>The Request Body is</li>
  </ol>
  <pre><code>{
       &quot;data&quot;:{
            &quot;username&quot;: &quot;username_string&quot;,
            &quot;password&quot;: &quot;password_string&quot;
       }
  }
  </code></pre>
  <ol start="5">
  <li>I've tried these clearing caches, and doing <code>composer dump-autoload</code> and the problem still persists</li>
  </ol>