Find file
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (49 sloc) 2.1 KB


alt text

PHP biceps cURL :)

Following is the PHP cURL wrapper class which I use to make GET and POST requests. The examples are below. Disclamer: be sure that you have permission to scrape and use the content you're after.

Simple GET request


$googleHTML = CurlWrapper::SendRequest('');
echo $googleHTML;

If you're a firm non-static lover here's a "normal" class simple GET request usage:


$curl = new CurlWrapper();
$googleHTML = $curl->SendRequest('');
echo $googleHTML;

JSON POST request

Here's an example of sending a JSON POST request to imaginitive URL '' with some data array:


$cookieSettingUrl = '';
$cookie = CurlWrapper::SendRequest($cookieSettingUrl);

$data = array(
    "year" => 2014,
    "day" => 3,
    "month" => 4,
    "id" => 20
$postData = json_encode($data);

$jsonUrl = '';
$headers = array('Accept: application/json','Content-Type: application/json');

$resultsHTML = CurlWrapper::SendRequest($jsonUrl, $cookieSettingUrl, "POST", $postData, $headers);
$resultsJson = json_decode($resultsHTML);

Important to note is that you have to add proper $headers array, and that you json_encode your &data array as shown when POSTing to a service which expects JSON data.


The reason why I first used these two lines:

$cookieSettingUrl = '';
$cookie = CurlWrapper::SendRequest($cookieSettingUrl);

is to set any cookies (and you will find that some services do this) that may be needed to be sent along with the request to ''. Cookies are set to 'curlCookies.txt' in the CurlWrapper_* class. You can change this to your liking, and you have to make sure that you set proper permissions for this file.

Hope this proves useful to someone.