MetaPhilter Doc

« TOC

HTTP Request API

MetaPhilter includes a class to execute HTTP requests.

The constructor of the httpRequest class:

httpRequest(string $url [, string $method [, string $data [, array $headers] ] ])

The $headers parameter should be an array of strings with standard HTTP headers (e.g. 'Content-Type: text/xml')

If $data is specified, a 'Content-Length' header is automatically sent to the server in the header block.

The resulting object will have four member variables:

To make a simple GET request:

$response=new httpRequest('http://google.com/');
print $response->content;

To POST some data:

$response=new httpRequest('http://non-existant.com/post.php',
                          POST,
                          '<?xml version="1.0"?>
                           <cms>MetaPhilter</cms>',
                          array('Content-Type: text/xml'));

if ($response->headers['content-type']!='text/xml')
  print 'Incorrect data return!';
else 
  print $response->content;