Использование жрет с Laravel не возвращает ответ - PullRequest
0 голосов
/ 12 января 2019

Я разработал веб-сервис с Laravel фреймворком, который использует пакет guzzle/guzzle для создания токена, и он отлично работал на хосте. Поскольку я переместил свой веб-сервис с хоста на сервер CentOS, он не может вернуть токен. Это мой код для создания токена:

        $client   = new GuzzleClient();
        $response = $client->request('POST', env('APP_URL') . '/oauth/token', [
            RequestOptions::JSON => [
                "username"       => $username,
                "password"       => $password,
                "grant_type"     => "password",
                "client_id"      => 3,
                "client_secret"  => "iUwyfTzdf37JPJ6qYGDegmUWbYmZl3a6YGxywrud",
                "theNewProvider" => "subscribers"
            ]
        ]);

        return $response;

Когда я вызываю свой веб-сервис с Postman, это ответ:

Could not get any response
There was an error connecting to http://x.x:x/api/authenticate.
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Proxy configured incorrectly
Ensure that proxy is configured correctly in Settings > Proxy
Request timeout:
Change request timeout in Settings > General

И я настроил Postman, как он сказал, но ничего не изменилось. Я не знаю причину.

Когда я печатаю ответ, он выглядит так:

GuzzleHttp\Psr7\Response Object
(
    [reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
    [statusCode:GuzzleHttp\Psr7\Response:private] => 200
    [headers:GuzzleHttp\Psr7\Response:private] => Array
        (
            [Date] => Array
                (
                    [0] => Sat, 12 Jan 2019 06:23:26 GMT
                )

            [Server] => Array
                (
                    [0] => Apache/2.2.15 (CentOS)
                )

            [X-Powered-By] => Array
                (
                    [0] => PHP/7.2.13
                )

            [Access-Control-Allow-Origin] => Array
                (
                    [0] => *
                )

            [Link] => Array
                (
                    [0] =>
<http://x.x/wp-json/>; rel="https://api.w.org/"
                    [1] =>
<http://x.x/>; rel=shortlink
                )

            [Connection] => Array
                (
                    [0] => close
                )

            [Transfer-Encoding] => Array
                (
                    [0] => chunked
                )

            [Content-Type] => Array
                (
                    [0] => text/html; charset=UTF-8
                )

        )

    [headerNames:GuzzleHttp\Psr7\Response:private] => Array
        (
            [date] => Date
            [server] => Server
            [x-powered-by] => X-Powered-By
            [access-control-allow-origin] => Access-Control-Allow-Origin
            [link] => Link
            [connection] => Connection
            [transfer-encoding] => Transfer-Encoding
            [content-type] => Content-Type
        )

    [protocol:GuzzleHttp\Psr7\Response:private] => 1.1
    [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
        (
            [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #648
            [size:GuzzleHttp\Psr7\Stream:private] => 
            [seekable:GuzzleHttp\Psr7\Stream:private] => 1
            [readable:GuzzleHttp\Psr7\Stream:private] => 1
            [writable:GuzzleHttp\Psr7\Stream:private] => 1
            [uri:GuzzleHttp\Psr7\Stream:private] => php://temp
            [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
                (
                )

        )

)

Я использовал CURL для проверки ответа веб-службы и получил следующую ошибку:

curl error 56 illegal or missing hexadecimal sequence in chunked-encoding
...