当我使用Requests
在我聪明的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' james /桌面/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
EDIT-1
我一直在关注GitHub文档,但不确定在哪里可以触发此问题。
答案 0 :(得分:0)
与大多数现代PHP库一样,该库依赖于自动加载。如果您使用的是作曲家,则可以免费获得。如果是手动安装,则需要照顾自动装带器。如文档所述:
并将其包含在脚本中:
require_once '/path/to/Requests/library/Requests.php';
您可能还需要注册一个自动加载器:
Requests::register_autoloader();