Here is my full working function, in case it helps you any 🙂
function execute_requests($server, $path, $qstring, $username, $password) {
/* Set up cURL with curl_init. $ch is for Curl Handle. */
$ch = curl_init();
/* Set username/password for request */
curl_setopt($ch, CURLOPT_USERPWD, "$username" . ":$password");
/* Set the type of request to POST */
curl_setopt($ch, CURLOPT_POST, 1);
/* Suppress header in cURL's output */
curl_setopt($ch, CURLOPT_HEADER, 0);
/* Make curl return the results to a variable instead of STDOUT */
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
/* Set maximum time for cURL request */
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
/* Construct request */
$requestedurl = "$server" . "/$path";
/* Set URL for request */
curl_setopt($ch, CURLOPT_URL, "$requestedurl");
/* Set query string for post request */
curl_setopt($ch, CURLOPT_POSTFIELDS, "$qstring");
/* Execute request */
$result = curl_exec($ch);
if(curl_error($ch)) {
echo "Error retrieving <b>$requestedurl </b>";
exit;
}
curl_close ($ch);
return $result;
}