我已经开发了一个Laravel
框架的Web服务,该框架使用guzzle/guzzle
包来创建令牌,并且在主机上运行良好。由于我已将Web服务从主机移至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
调用Web服务时,这是响应:
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检查我的Web服务响应,但出现以下错误:
curl error 56 illegal or missing hexadecimal sequence in chunked-encoding