简体   繁体   English

致命错误:在 C:\\xampp\\htdocs\\test 中找不到“HttpRequest”类

[英]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.

相关问题 提交后:PHP致命错误:在C:\\ xampp \\ htdocs \\中找不到类 - After submit: PHP Fatal error: Class not found in C:\xampp\htdocs\ PHP致命错误:在C:\\ xampp \\ htdocs \\中找不到类 - PHP Fatal error: Class not found in C:\xampp\htdocs\ 致命错误:在C:\\ xampp \\ htdocs中找不到类&#39;BaseController&#39; - Fatal error: Class 'BaseController' not found in C:\xampp\htdocs PHP致命错误:在C:\\ xampp \\ htdocs \\中找不到类“线程化” - PHP Fatal error: Class 'Threaded' not found in C:\xampp\htdocs\ PHP 致命错误:未捕获错误:Class 在 C:\xampp\htdocs\server\pdf.php:5 中未找到“Mpdf\Mpdf” - PHP Fatal error: Uncaught Error: Class "Mpdf\Mpdf" not found in C:\xampp\htdocs\server\pdf.php:5 致命错误:在C:\\ xampp \\ htdocs \\ shapeway.php中找不到类&#39;oauth&#39; - Fatal error: Class 'oauth' not found in C:\xampp\htdocs\shapeway.php 致命错误:在第633行的C:\\ xampp \\ htdocs \\ libraries \\ cms \\ application \\ cms.php中找不到类&#39;JApplicationHelper&#39; - Fatal error: Class 'JApplicationHelper' not found in C:\xampp\htdocs\libraries\cms\application\cms.php on line 633 致命错误:在第49行的C:\\ xampp \\ htdocs \\ portfolio \\ actions \\ addProject_action.php中找不到类&#39;finfo&#39; - Fatal error: Class 'finfo' not found in C:\xampp\htdocs\portfolio\actions\addProject_action.php on line 49 php线程可以在cmd中正常运行,但不能在浏览器中运行。 并给出“致命错误:在第二行的C:\\ xampp \\ htdocs \\ test.php中找不到类&#39;线程&#39;”错误 - php thread properly run in cmd but don't run in browser. And gives “Fatal error: Class 'Thread' not found in C:\xampp\htdocs\test.php on line 2” error 致命错误:未捕获的错误:在C:\\ xampp \\ htdocs \\ code \\ project \\ routes \\ web.php中找不到类“ Route”:18 - Fatal error: Uncaught Error: Class 'Route' not found in C:\xampp\htdocs\code\project\routes\web.php:18
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM