Libcurl is a great library with a whole host of features. In PHP it is accessible with the php_curl extension. Although it’s fully features it has a rather ugly and clumsy api. Added to this php_curl is often not part of the default install of PHP.
There is another option. In PHP you probably know you can do requests with the streams extension and use functions like file_get_contents to retrieve a url contents.
<?php
$page = file_get_contents('http://fishtrap.co.uk');
Since PHP 5.0 you can also set a stream_context to include POST data. This can include files and other multipart form data.
I created a short script to try add a more intuitive and usable wrapper around the functions. To use it you just need to do:
<?php
include('StreamsHttpPost.php');
$request = new StreamsHttpPost('http://example.com');
$data = array(
'foo' => 'bar',
'baz' => 'bat',
);
$request->addFile('picture', 'path/to/file');
$page = $request->post($data);
var_dump($request->getResponseCode()); // int(302)
This will then send a post request as if the user had submitted a form with the form fields.
The code is here on github. Comments, pull requests and corrections welcome.