php - 致命错误:未捕获的错误:使用请求时未找到类“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 文档,但我不确定引发这个问题的原因在哪里。
解决方案
与大多数现代 PHP 库一样,该库依赖于自动加载。如果你使用作曲家,你可以免费获得。如果您手动安装它,则需要注意自动加载器。正如文档所述:
并将其包含在您的脚本中:
require_once '/path/to/Requests/library/Requests.php';
您可能还想注册一个自动加载器:
Requests::register_autoloader();
推荐阅读
- javascript - 单击外部组件时关闭弹出窗口
- ios - 使用 SwiftUI 创建手势以编辑列表项
- react-native - 从我的反应本机应用程序中关闭正在运行的应用程序
- reactjs - Draft-js 更好的方法来保存和检索 MySql 中的内容
- python - 如何在 Pandas DataReader 中修复此 RemoteDataError
- php - PHP sql查询没有向前端返回正确的行数
- java - 从 Java 重构到 Kotlin,遇到泛型问题
- javascript - 在 Service Worker 中缓存 Amazon S3 文件以供离线使用
- java - void android.widget.TextView.setText(java.lang.CharSequence)' 在 Home.onCreate 的空对象引用上
- javascript - 基于 JQuery Prototype 的范围解析抛出 NaN 错误