【发布时间】:2023-03-19 04:31:01
【问题描述】:
在我的 Laravel 应用程序中,作为计划任务,我想在我的自定义类中发出 Http 请求,但我得到了
Class 'Illuminate\Support\Facades\Http' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'Illuminate\\Support\\Facades\\Http' not found
这是我的自定义类
<?php
namespace App\MyModels\GetData;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class Test
{
public function __invoke()
{
Log::info("Cron executed : ");
$response = Http::get("https://google.com");
Log::info(print_r($response, true));
}
}
在 Laravel 文档中,它说:
要发出请求,您可以使用 get、post、put、patch 和 delete 方法。首先,我们来看看如何发出一个基本的 GET 请求:
使用 Illuminate\Support\Facades\Http;
$response = Http::get('http://test.com');
【问题讨论】:
-
Http不是我所知道的外观。您在其使用方面参考了哪些文档? -
@TimLewis 在这里laravel.com/docs/7.x/http-client。我刚刚在我的问题中添加了它的解释
-
啊,原来是
GuzzleHttp;凉爽的。我对此很熟悉。您是否运行了 composer 命令?composer require guzzlehttp/guzzle -
@TimLewis 是的,我做到了!
-
好的,下一步;运行
composer dump-autoload,以防万一没有更新。之后,再试一次,如果还是不行,则执行php artisan tinker,然后执行$http = new Illuminate\Support\Facades\Http();;它应该输出一些东西。尝试过之后告诉我。
标签: laravel httprequest