Can’t make HTTP Post request response: GuzzleHttpPsr7Response "Not Acceptable"

  api, http, illuminate, laravel, php

I’m trying to make a post http request using IlluminateSupportFacadesHttp.

My request :

$response = Http::post(
            $this->api.'/auth',
            [
                'auth' => [
                    'username' => $this->username,
                    'password' => $this->password
                ]
            ]
        )->json('response');

While api,username and password are set in a __construct method.

This request is working well in postman. But when I run it on php server I get a null.
I digged in the response and I found the following :

IlluminateHttpClientResponse {#2741 ▼
  #response: GuzzleHttpPsr7Response {#2766 ▼
    -reasonPhrase: "Not Acceptable"
    -statusCode: 406
    -headers: array:5 [▼
      "Server" => array:1 [▶]
      "Date" => array:1 [▶]
      "Content-Type" => array:1 [▶]
      "Content-Length" => array:1 [▶]
      "Connection" => array:1 [▶]
    ]
    -headerNames: array:5 [▼
      "server" => "Server"
      "date" => "Date"
      "content-type" => "Content-Type"
      "content-length" => "Content-Length"
      "connection" => "Connection"
    ]
    -protocol: "1.1"
    -stream: GuzzleHttpPsr7Stream {#2765 ▼
      -stream: stream resource @28 ▶}
      -size: null
      -seekable: true
      -readable: true
      -writable: true
      -uri: "php://temp"
      -customMetadata: []
    }
  }

Do you have an idea on how to solve this ?

Source: Laravel

Leave a Reply