在 php 中找不到 HttpRequest
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18579407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HttpRequest not found in php
提问by Moustafa Mohamed
I just want to make a httprequest with post parameters. I used this code
我只想用 post 参数创建一个 httprequest。我用了这个代码
$r = new HttpRequest($url, HttpRequest::METH_POST);
$r->send();
but I get this error:
但我收到此错误:
ErrorException [ Fatal Error ]: Class 'HttpRequest' not
ErrorException [致命错误]:类 'HttpRequest' 不是
I added extension=php_http.dll
this to my php.ini, but the problem still exists.
I download the php_http.dll file and inserted it in the ext folder of php but it was already existing so I replaced and still have the same problem.
我把extension=php_http.dll
这个加到我的 php.ini 中,但问题仍然存在。我下载了 php_http.dll 文件并将其插入到 php 的 ext 文件夹中,但它已经存在,所以我替换了它,但仍然存在同样的问题。
Any help would be appreciated
任何帮助,将不胜感激
回答by guyver4mk
If you are using php 5.4 or above, there does not seem to be a php_http.dll file to include in your extensions library (Unless someone can find one that I missed??).
如果您使用的是 php 5.4 或更高版本,则您的扩展库中似乎没有 php_http.dll 文件(除非有人能找到我遗漏的文件??)。
The only one that I could find generated errors on starting up the Apache server after updating the php.ini configuration file to include the extension.
在更新 php.ini 配置文件以包含扩展名后,我在启动 Apache 服务器时发现生成错误的唯一一个。
Fear not however, as there seems to be a GitHub Project which provides the functionality within a class, rather than an extension. Click here to find the required class.
但是不要害怕,因为似乎有一个 GitHub 项目在类中提供功能,而不是扩展。单击此处查找所需的课程。
If you save this class in your project and call like so;
如果您将这个类保存在您的项目中并像这样调用;
include_once('HttpRequest.php'); //where HttpRequest.php is the saved file
$url= 'http://www.google.com/';
$r = new HttpRequest($url, "POST");
var_dump($r->send());
Failing that, it would seem that the only other viable option would be to compile the .dll yourself from the source here:(
如果做不到这一点,似乎唯一的其他可行选择是自己从这里的源代码编译 .dll :(
Otherwise, another option would be to use cURL instead. cURL provides most (if not all) of the functionality of the httpRequest
.
否则,另一种选择是改用 cURL。cURL 提供了httpRequest
.
A simple example of this would be;
一个简单的例子是;
$url = "http://www.google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body
$head = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
var_dump($head);
More details and better examples can be found on the php website Here
更多细节和更好的例子可以在 php 网站上找到这里
I hope this helps answer your question, rather than leave you with more...
我希望这有助于回答您的问题,而不是给您留下更多...
回答by user555
You need to make sure you have a php_http.dll
that matches your PHP version. You can do <?php phpinfo();
to check with extensions are loaded (look for "http", it will list the version and available classes).
您需要确保您php_http.dll
的 PHP 版本匹配。您可以<?php phpinfo();
检查是否加载了扩展(查找“http”,它会列出版本和可用类)。
If the extension does not appear in phpinfo()
, you should check your logs to learn where the problem comes from or run the PHP binary directly from the command prompt — php -i
. If there is any error loading a dynamic library it will show up in a dialog box. Note that PHP will still continue to function even though an extension failed to load.
如果扩展没有出现在 中phpinfo()
,您应该检查您的日志以了解问题的来源或直接从命令提示符运行 PHP 二进制文件 — php -i
。如果加载动态库时出现任何错误,它将显示在对话框中。请注意,即使扩展加载失败,PHP 仍将继续运行。
回答by tony gil
you can reinstall the package
你可以重新安装这个包
$ pecl install -f pecl_http-1.7.6
or access the data using curl like this snippet
或者像这个片段一样使用 curl 访问数据