/PHP
Last active
September 4, 2017 21:49
-
-
Save wilcorrea/dd2c07a8df9a7d12ce918cb2f7e3f979 to your computer and use it in GitHub Desktop.
Autenticação Digest usando PHP POST para Web Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error_reporting(E_ALL); | |
ini_set( 'display_errors','1'); | |
$url = "http://192.168.0.90:8088/asterisk/amxml?Action=QueueStatus&Queue=8889&Member=Agent/19513"; | |
$username = "dashboard_enel"; | |
$password = "enel@890678"; | |
$options = array( | |
CURLOPT_HTTPHEADER => array('Authorization: Basic '. base64_encode($username . ":" . $password)) | |
CURLOPT_URL => $url, | |
CURLOPT_HEADER => true, | |
CURLOPT_VERBOSE => true, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_SSL_VERIFYPEER => false, // for https | |
CURLOPT_USERPWD => $username . ":" . $password, | |
CURLOPT_HTTPAUTH => CURLAUTH_DIGEST, | |
); | |
$ch = curl_init(); | |
curl_setopt_array( $ch, $options ); | |
try { | |
$raw_response = curl_exec( $ch ); | |
// validate CURL status | |
if(curl_errno($ch)) | |
throw new Exception(curl_error($ch), 500); | |
// validate HTTP status code (user/password credential issues) | |
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($status_code != 200) | |
throw new Exception("Response with Status Code [" . $status_code . "].", 500); | |
} catch(Exception $ex) { | |
if ($ch != null) curl_close($ch); | |
throw new Exception($ex); | |
} | |
//if ($ch != null) curl_close($ch); | |
echo "raw response: " . $raw_response; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment