首页 > 解决方案 > 致命错误:未捕获的错误:使用请求时未找到类“Requests_Hooks”

问题描述

当我使用请求时

在我聪明的test.php文件中:

require_once($_SERVER['DOCUMENT_ROOT'] . '/libs/src/Requests/library/Requests.php');

$headers = array('Accept'=>'application/json', 'Authorization' => 'Bearer AwSBtNOd3Fw4NkDUDdoZqqwFOCKDxi');
$request = Requests::get('http://localhost:8000/amodel/list/', $headers, []);

$res = array(
    'status'=>var_dump($request->status_code),
    'data'=>var_dump($request->body)
);

$smarty->assign('res', $res);

$smarty->display('test.tpl');

但是当我访问时test.php,出现致命错误:

致命错误:未捕获的错误:在 /Users/james/Desktop/TestPHP/smarty-test02/libs/src/Requests/library/Requests.php:568 中找不到类“Requests_Hooks” 堆栈跟踪:#0 /Users/james/Desktop /TestPHP/smarty-test02/libs/src/Requests/library/Requests.php(363): Requests::set_defaults(' http://localhos ...', Array, NULL, 'GET', Array) #1 /Users/james/Desktop/TestPHP/smarty-test02/libs/src/Requests/library/Requests.php(231): Requests::request(' http://localhos ...', Array, NULL, 'GET ', Array) #2 /Users/james/Desktop/TestPHP/smarty-test02/test.php(36): Requests::get(' http://localhos ...', Array, Array) #3 {main在第 568 行的 /Users/james/Desktop/TestPHP/smarty-test02/libs/src/Requests/library/Requests.php 中抛出


编辑-1

我一直在关注 GitHub 文档,但我不确定引发这个问题的原因在哪里。

标签: phphttprequest

解决方案


与大多数现代 PHP 库一样,该库依赖于自动加载。如果你使用作曲家,你可以免费获得。如果您手动安装它,则需要注意自动加载器。正如文档所述:

并将其包含在您的脚本中:

require_once '/path/to/Requests/library/Requests.php';

您可能还想注册一个自动加载器:

Requests::register_autoloader();

推荐阅读