[英]Fatal error: Class 'HttpRequest' not found in C:\xampp\htdocs\test
In my website am using infobip 2-Factor Authentication for security purpose.在我的网站中,出于安全目的,我使用infobip 2-Factor Authentication 。 I got some code in their website it showing error like我在他们的网站上得到了一些代码,它显示了类似的错误
Fatal error: Class 'HttpRequest' not found in C:\xampp\htdocs\test\OTP\send.php on line 2
Code is following:代码如下:
Send.php发送.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;
}
?>
This following code for request and this also showing以下请求代码,这也显示
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;
}
?>
Ok say you have a file HttpRequest.php in the same folder and in that file is好的说你在同一个文件夹中有一个文件 HttpRequest.php 并且在那个文件中
class HttpRequest {
...
}
Then somewhere before calling it, you need to tell php about it.然后在调用它之前的某个地方,您需要将它告诉 php。 This is done using one of four ways, but I would do it this way这是使用四种方式之一完成的,但我会这样做
require_once __DIR__.'/HttpRequest.php'; //assuming it's in the same folder.
Remember this isn't magic, it's just computer code.请记住,这不是魔术,它只是计算机代码。 It only knows what you tell it.它只知道你告诉它什么。 I would also hope that the place you got the code from would have some kind of basic instructions on how to install set it up, and that you read that.我还希望您获得代码的地方有一些关于如何安装设置的基本说明,并且您阅读了这些说明。
Now not to confuse you but the choices are现在不要混淆你,但选择是
include
include_once
require
require_once
I only put these here to illustrate that, things ( generally ) mean what they say in programing.我把这些放在这里只是为了说明,事物(通常)意味着他们在编程中所说的。 So include, includes it, adding *_once, only does it once, and require will throw an error if it's not found in the location specified, thus making it required.所以包含,包含它,添加*_once,只做一次,如果在指定的位置找不到它,require将抛出错误,从而使其成为必需的。 Whereas include doesn't really care if it was actually included or not.而 include 并不真正关心它是否真的被包含。
Good Luck!祝你好运! happy coding.快乐编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.