在php中找不到HttpRequest

在php中找不到HttpRequest

问题描述:

我只想使用post参数创建一个httprequest.我使用了这段代码

I just want to make a httprequest with post parameters. I used this code

$r = new HttpRequest($url, HttpRequest::METH_POST);
$r->send();

但我收到此错误:

ErrorException [致命错误]:不是类'HttpRequest'

ErrorException [ Fatal Error ]: Class 'HttpRequest' not

我将extension=php_http.dll添加到了我的php.ini中,但问题仍然存在. 我下载了php_http.dll文件,并将其插入到php的ext文件夹中,但是它已经存在,因此我进行了替换,仍然有同样的问题.

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.

任何帮助将不胜感激

如果您使用的是php 5.4或更高版本,则扩展库中似乎没有php_http.dll文件(除非有人可以找到该文件)我错过了??).

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.ini配置文件以包括扩展名之后,我发现启动Apache服务器时出现的唯一错误.

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.

但是请不要害怕,因为似乎有一个GitHub Project提供了类中的功能,而不是扩展. 单击此处查找所需的类.

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.

如果您将此类保存在项目中,然后像这样调用;

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());

否则,似乎唯一可行的选择是从此处源自己编译.dll. >:(

Failing that, it would seem that the only other viable option would be to compile the .dll yourself from the source here :(

否则,另一种选择是改用cURL. cURL提供httpRequest的大多数(如果不是全部)功能.

Otherwise, another option would be to use cURL instead. cURL provides most (if not all) of the functionality of the httpRequest.

一个简单的例子是

$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);

更多详细信息和更好的示例可以在php网站上找到此处

More details and better examples can be found on the php website Here

我希望这有助于回答您的问题,而不是给您留下更多...

I hope this helps answer your question, rather than leave you with more...