Created
July 25, 2014 01:59
-
-
Save djaney/dee527406e875ad09808 to your computer and use it in GitHub Desktop.
Basic Authentication in post request
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
function getAuthString(){ | |
return base64_encode($username.':'.$password); | |
} | |
function sendRequest($params){ | |
$headers = array( | |
'Authorization: Basic '.getAuthString(), | |
'Content-Type: application/json', | |
); | |
$ch = curl_init(); | |
$url = getURL(); | |
curl_setopt($ch, CURLOPT_URL, $url ); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); | |
curl_setopt($ch, CURLOPT_POST, 1 ); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params) ); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$result=curl_exec ($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment