【发布时间】:2015-09-25 20:22:58
【问题描述】:
在我的网站中,出于安全目的,我使用 infobip 2-Factor Authentication。我在他们的网站上有一些代码显示错误,例如
Fatal error: Class 'HttpRequest' not found in C:\xampp\htdocs\test\OTP\send.php on line 2
代码如下:
发送.php
<?php
$request = new HttpRequest();
$request->setUrl('https://oneapi.infobip.com/2fa/1/pin');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array
('accept' => 'application/json'
,'content-type' => 'application/json'
,'authorization' => 'App SECRET_KEY'));
$request->setBody('{
"applicationId": "YOUR_APPLICATION_ID",
"messageId": "YOUR_MESSAGE_ID",
"to": "PHONE_NUMBER"
}');
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
下面的请求代码,这也显示了
Fatal error: Class 'HttpRequest' not found in C:\xampp\htdocs\test\OTP\request.php on line 3
request.php
<?php
$request = new HttpRequest();
$request->setUrl('https://oneapi.infobip.com/2fa/1/pin/{PIN_ID}/verify');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array('accept' => 'application/json', 'content-type' => 'application/json','authorization' => 'App YOUR_API_KEY'
));
$request->setBody('{"pin": "PIN_CODE"}');
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
【问题讨论】:
-
这是因为包含该类的文件尚未使用 include 或 require 加载。从字面上看,HttpRequest 类在被包含之前对 php 没有任何意义。
-
你的意思是我想在这里添加一些文件...?
-
您希望拥有包含该类的文件,然后添加类似 include 'pathtoHttpReques';
-
@NishaChinnapa 您是否在本地尝试这些代码?我的意思是
localhost? -
这可能是问题
Not including the appropriate file or mismatch path, (Infobip will have a bulk of folders for sending sms)忠告尝试在线触发文件,我相信你也安装了composer的infobip
标签: php httprequest infobip infobip-api