問題描述:
- 我有一個berer api。我只需要使用實際發出請求并接收回應的控制器來傳遞請求。(注意:不使用郵遞員)
我的 API 根是這樣的: http://localhost/cloud/website/api/v1/
在 api.php
Route::group(['prefix' => 'v1'], function() {
Route::group(['middleware' => 'auth:sanctum'], function() {
Route::post('entries/sync-info', [EntrySyncInfoController::class, 'index']);
}
}
我正在嘗試從 API 獲得回應,但不斷收到 500 SERVER ERROR。
$token ='24|cbG3w1ONkxxeUBhLCGwFjOSLk......';
$response = $client->request('GET', 'http://localhost/cloud/website/api/v1/entries?perPage=50', [
'headers' => [
'Authorization' => 'Bearer '.$token,
'Accept' => 'application/json',
],
]);
return $response->body();
但是當我向 Postman 提出請求時,它給了我一個完美的回應。
郵遞員請求的圖片在這里
另外,當我直接在瀏覽器上點擊這個 url 時,它說同樣的錯誤。
我也關注這個問題。它回傳空值。
我該如何解決這個問題?如何使用不記名令牌獲得回應?
uj5u.com熱心網友回復:
$response = $client->get('http://localhost/cloud/website/api/v1/entries?perPage=50', [
'headers' => [
'Authorization' => 'Bearer '.$token,
'Accept' => 'application/json',
],
]);
參考:見這篇文章,也看看這個
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/335285.html
上一篇:檢查是否在遷移中
