PHP HTTP-Request

JNK picture JNK · Dec 30, 2010 · Viewed 39.8k times · Source

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?

Answer

Vojta picture Vojta · Dec 30, 2010

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