One alternative would be to use PHPs Stream functions instead of curl
http://www.php.net/manual/en/ref.stream.php
Your code would look something like
$url = "http://some-restful-client/";
$params = array('http' => array(
'method' => "GET",
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp)
{
throw new Error("Problem with ".$url);
}
$response = @stream_get_contents($fp);
if ($response === false)
{
throw new Error("Problem reading data from ".$url);
}
echo $response //this is the contents of your request;
You need to be using PHP 4 >= 4.3.0 or PHP 5 tho
UPDATE:
I wrapped this into a quick class for you. To use it, do something like the following
$hr = new HTTPRequest("http://someurl.com", "GET");
try
{
$data = $hr->send();
echo $data;
}
catch (Exception $e)
{
echo $e->getMessage();
}
Here is the code for the class. You can also pass data into the 3rd and 4th parameters of the constructor to set post data and headers accordingly. Note post data should be a string not an array, headers should be an array with the keys being the name of the header
Hope this helps!!!
<?php
/**
* HTTPRequest Class
*
* Performs an HTTP request
* @author Adam Phillips
*/
class HTTPRequest
{
public $url;
public $method;
public $postData;
public $headers;
public $data = "";
public function __construct($url=null, $method=null, $postdata=null, $headers=null)
{
$this->url = $url;
$this->method = $method;
$this->postData = $postdata;
$this->headers = $headers;
}
public function send()
{
$params = array('http' => array(
'method' => $this->method,
'content' => $this->data
));
$headers = "";
if ($this->headers)
{
foreach ($this->headers as $hkey=>$hval)
{
$headers .= $hkey.": ".$hval."\n";
}
}
$params['http']['header'] = $headers;
$ctx = stream_context_create($params);
$fp = @fopen($this->url, 'rb', false, $ctx);
if (!$fp)
{
throw new Exception("Problem with ".$this->url);
}
$response = @stream_get_contents($fp);
if ($response === false)
{
throw new Exception("Problem reading data from ".$this->url);
}
return $response;
}
}
?>