5

I have MAMP Pro installed running php 5.2.13. When I try to initialize a HTTP-Request

$r = new HttpRequest('http://example.com/', HttpRequest::METH_GET);

it tells me:

"Class 'HttpRequest' not found in ...".

What do I need to do to 'install(?)' it?

Neil Townsend
  • 6,024
  • 5
  • 35
  • 52
JNK
  • 1,753
  • 8
  • 25
  • 37

3 Answers3

6

Contemporary Answer for MAMP 2.0 and HTTP_Request2:

Go into your MAMP/bin/php/php5.3.6/bin/ and run

./pear install --alldeps HTTP_Request2

Restart your server and test with the following code, from the PEAR repository:

<?php
require_once 'HTTP/Request2.php';

$request = new HTTP_Request2('http://pear.php.net/', HTTP_Request2::METHOD_GET);
try {
    $response = $request->send();
    if (200 == $response->getStatus()) {
        echo $response->getBody();
    } else {
        echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
             $response->getReasonPhrase();
    }
} catch (HTTP_Request2_Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

Don't forget the require_once statement!

Philip
  • 655
  • 8
  • 12
6

You must enable http extension:

http://www.php.net/manual/en/http.setup.php

Or you can try new HTTP_Request2:

sudo pear install --alldeps HTTP_Request2-alpha

And then:

$req = new HTTP_Request2('your.url');
$req->setMethod('POST');
$req->setHeader("content-type", $mimeType);
$req->setBody('');
$response = $req->send();
Vojta
  • 23,061
  • 5
  • 49
  • 46
  • I think I have to install it first... When I run the command "pecl install pecl_http" it gives me an error saying "checking for event.h... not found configure: WARNING: continuing without libevent support checking for magic.h... not found configure: error: could not find magic.h"... What now? – JNK Dec 31 '10 at 12:46
  • Which platform are you using ? Which version of PHP ? – Vojta Jan 01 '11 at 16:23
  • @Vojta I'm running MAMP (Mac 10.6.5 / Unix) PHP v5.2.13 AND/OR PHP v5.3.2 – JNK Jan 04 '11 at 01:07
  • @JNK: sorry for delay.... Maybe, it's looking for eventlib on wrong place, I guess it has been installed by macports, so it's under /opt/local/, so try to install http extension by macports... – Vojta Jan 17 '11 at 00:15
  • ... because default location is probably under /usr/local – Vojta Jan 17 '11 at 00:24
2

You need to enable the extension ...

add the following to your php.ini

extension = php_http.dll

Apparently that was asked a lot:

http://php.bigresource.com/Track/php-33sNme7A/

Andrey Voev
  • 265
  • 3
  • 8