I just want to make a httprequest with post parameters. I used this code
$r = new HttpRequest($url, HttpRequest::METH_POST);
$r->send();
but I get this error:
ErrorException [ Fatal Error ]: Class 'HttpRequest' not
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.
Any help would be appreciated
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??).
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.
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());
Failing that, it would seem that the only other viable option would be to compile the .dll yourself from the source here :(
Otherwise, another option would be to use cURL instead. cURL provides most (if not all) of the functionality of the 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
I hope this helps answer your question, rather than leave you with more...
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).
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.
you can reinstall the package
$ pecl install -f pecl_http-1.7.6
or access the data using curl like this snippet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With