我正在项目中将 Guzzle 设置为 Laravel 6 的 HTTP 客户端。它工作得很好,并且对每个 API 命中都给出了响应。但突然它返回“Call to a member function getStatusCode() on null”错误。
我尝试使用 Postman 和curl 来访问API,当Guzzle 不返回时,它们会返回正确的响应。
RequestException 响应的 print_r 不返回响应,而是返回 null。
我尝试调试REST API 以测试使用 Guzzle 命中请求时请求的去向,但请求甚至没有命中目标函数。
这是我的 Guzzle 代码:
class ApiCallback
{
public static function request($method, $uri, $params = [], $useAccessToken = true){
$client = new \GuzzleHttp\Client();
$response = null;
$jsonObj = null;
try{
if($useAccessToken){
$response = $client->request(
strtoupper($method),
$uri,
[
"headers" =>[
'Accept' => '*/*',
"Authorization" => "Bearer ".Session::get('access_token'),
'Content-Type' => 'application/json',
'User-Agent' => 'saranaku-'.Session::get('id'),
'Content-Length' => '0',
'Accept-Encoding' => 'gzip, deflate, br',
'Connection' => 'keep-alive'
]
,
"body" => \json_encode(
$params
)
]
);
}
附加信息:
REST API 正在本地主机中运行,端点为:/v1/login
HTTP 方法是 POST
REST API 使用 Java Spring Boot v1.5.6
请求正文是
{
"data":{
"username": "username_string",
"password": "password_string"
}
}
我已经尝试过清除缓存,但composer dump-autoload问题仍然存在
慕标5832272
拉莫斯之舞