简体   繁体   English

致命错误:即使在php.ini中加载了pecl_http之后,也找不到类'HttpResponse'

[英]Fatal error: Class 'HttpResponse' not found even after pecl_http loaded in php.ini

I have installed and loaded PECL http extension. 我已经安装并加载了PECL http扩展名。

I have added these lines in php.ini: 我在php.ini中添加了以下几行:

extension=raphf.so
extension=propro.so
extension=http.so

And I see the following being added in the output of 我看到以下内容被添加到

phpinfo()

HTTP Support enabled, Extension Version 2.0.4 启用HTTP支持,扩展版本2.0.4

libz 1.2.5 1.2.5 libz 1.2.5 1.2.5

libcurl 7.24.0 7.24.0 libcurl 7.24.0 7.24.0

libevent disabled disabled libevent已禁用已禁用

But when I try to use the class HttpResponse I am getting the error: 但是,当我尝试使用HttpResponse类时,出现了错误:

Fatal error: Class 'HttpResponse' not found in RequestHandler.php on line 21 致命错误:在第21行的RequestHandler.php中找不到类'HttpResponse'

Can anyone please guide to what I have missed. 谁能指导我错过的内容。

I figured it out. 我想到了。 YAY!! 好极了!!

I was installing pecl_http version 2 and testing methods from version 1. Version 2 has a completely different API than version 1. Who would have guessed :) 我正在安装pecl_http版本2和版本1的测试方法。版本2与版本1的API完全不同。谁会猜到:)

What about using code that doesn't require the PECL extension? 使用不需要PECL扩展名的代码怎么办?

For example this is something I used to retrieve a result back from a specially designed aspx file: 例如,这是我用来从特别设计的aspx文件中检索结果的东西:

function getLoginToken($dashboardUrl, $dashboardUsername, $dashboardPassword)
{
    $url = "{$dashboardUrl}GetLoginToken.aspx";
    $data = array('dashboardUsername' => $dashboardUsername,
            'dashboardPassword' => $dashboardPassword);
    $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($data),
            ),
            );

    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM