我正在尝试使用 Strapi API 部署我的 Laravel。离线时它工作正常,但在线时我收到错误。我尝试了一些方法,但没有进展。有人使用过 Laravel 和 Strapi 并在 Render 上部署了我的 Strapi 吗?
系统信息:
这是我的代码:
try {
$url = 'https://cono.onrender.com/api/majinas';
$response=json_decode(Http::get($url)->body());
// Debug the response
dd($response);
return view('welcome');
}
catch (\Exception $e) {
// Dump any exception details
dd($e->getMessage());
}
我什至尝试使用官方包,但仍然是同样的错误。将http更改为curl,但仍然是同样的问题。我认为问题在于如何允许它在在线时获取数据,因为它在离线状态下完美工作,或者当我尝试在浏览器上手动调用 API 时。
try {
$response = Http::withOptions(['verify' => false])
->get('https://cono.onrender.com/api/majinas');
if ($response->successful() && $response->json()):
dd($response->json);
endif;
return view('welcome');
} catch (\Exception $e) {
// Dump any exception details
dd($e->getMessage());
}