ubergeekzone
2/14/2016 - 9:47 PM

Comparison between Requests for PHP and CURL

Comparison between Requests for PHP and CURL

<?php
	
	// Requests for PHP Code
	$endpoint = "https://{$data['account']}.harvestapp.com/invoices";

	$hashAuth = base64_encode($data['username'].":".$data['password']);

	$response = Requests::get($endpoint, array('Content-Type' => 'application/json',
	'accept' => 'application/json',
	'authorization' => "Basic ". $hashAuth));

	return $response->body;
	
	//Non-Requests for PHP Code
 	$hashAuth = base64_encode($info['username'].":".$info['password']);

        $today_date = date("Y-m-d");
        $today_time = date("H:i:s");

        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://{$data['account']}.harvestapp.com/invoices",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => array(
                "accept: application/json",
                "authorization: Basic ".$hashAuth,
                "cache-control: no-cache",
                "content-type: application/json"
            ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);
        
        if(!$err) {
        return  $response;
        }
        
         curl_close($curl);
         
?>