收到“”cURL错误7:无法连接到cono.onrender.com端口443:https://xxx/api/majinas的连接被拒绝”

问题描述 投票:0回答:1

我正在尝试使用 Strapi API 部署我的 Laravel。离线时它工作正常,但在线时我收到错误。我尝试了一些方法,但没有进展。有人使用过 Laravel 和 Strapi 并在 Render 上部署了我的 Strapi 吗?

系统信息:

  • Strapi 版本:“4.16.2”
  • 操作系统:windows 10
  • 数据库:postgress
  • 节点版本:“>=18.0.0 <=20.x.x”

这是我的代码:

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 时。

php laravel api strapi
1个回答
0
投票
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());
}
© www.soinside.com 2019 - 2024. All rights reserved.