Curl

Various Curl Requests

GET w/ Auth Basic

$uriPath = "https://test.dev";

$client = curl_init($uriPath);
curl_setopt($curl, CURLOPT_HTTPGET, TRUE );  
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($curl, CURLOPT_VERBOSE, TRUE );  
curl_setopt($client, CURLOPT_TIMEOUT, 5);  
curl_setopt($client, CURLOPT_CONNECTTIMEOUT, 5);  
curl_setopt($client, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  
curl_setopt($client, CURLOPT_USERPWD, "$UserID:$Password");  

POST w/ Auth Basic

$postData = array(
     'Item1' => base64_encode($message),
     'Item2' => array('A','B', 'C')
);

$str_data = json_encode($postData);

$uriPath = "https://test.dev";

$client = curl_init($uriPath);
curl_setopt($client, CURLOPT_POST, 1);  
curl_setopt($client, CURLOPT_POSTFIELDS, $str_data);  
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($client, CURLOPT_HTTPHEADER, array(  
                    'Content-Type: application/json',
                    'Content-Length: ' . strlen($str_data)));
curl_setopt($client, CURLOPT_TIMEOUT, 5);  
curl_setopt($client, CURLOPT_CONNECTTIMEOUT, 5);  
curl_setopt($client, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  
curl_setopt($client, CURLOPT_USERPWD, "$UserID:$Password");  

PUT w/ Auth Basic

$postData = array(
     'Item1' => base64_encode($message),
     'Item2' => array('A','B', 'C')
);

$str_data = json_encode($postData);

$uriPath = "https://test.dev";

$client = curl_init($uriPath);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");  
curl_setopt($client, CURLOPT_POSTFIELDS, $str_data);  
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($client, CURLOPT_HTTPHEADER, array(  
                    'Content-Type: application/json',
                    'Content-Length: ' . strlen($str_data)));
curl_setopt($client, CURLOPT_TIMEOUT, 5);  
curl_setopt($client, CURLOPT_CONNECTTIMEOUT, 5);  
curl_setopt($client, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  
curl_setopt($client, CURLOPT_USERPWD, "$UserID:$Password");  

DELETE w/ Auth Basic

$uriPath = "https://test.dev";

$client = curl_init($uriPath);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");  
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($client, CURLOPT_HTTPHEADER, array(  
                    'Content-Type: application/json'));
curl_setopt($client, CURLOPT_TIMEOUT, 5);  
curl_setopt($client, CURLOPT_CONNECTTIMEOUT, 5);  
curl_setopt($client, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  
curl_setopt($client, CURLOPT_USERPWD, "$UserID:$Password");