Last active
September 21, 2015 10:34
-
-
Save randolphpebenito/c5ad47b17227a97b75ce to your computer and use it in GitHub Desktop.
HTTP POST JSON Data using PHP Curl (Login API)
This file contains hidden or 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
<?php | |
#FIXME: Hardcoded url | |
$url = 'http://kantokras.ph/api/account/login/'; | |
#Assumption: The params below have already been verified. | |
$topup_data = array("appCode" => "KantoKrasKing", | |
"msisdn" => "639178680114", | |
"password" => "abc123"); | |
#JSON encode the params | |
$topup_str = json_encode($topup_data); | |
#Curl init | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/json', | |
'Content-Length: '.strlen($topup_str) | |
) | |
); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $topup_str); | |
$result = curl_exec($ch); | |
#Ensure to close curl | |
curl_close($ch); | |
#For verbosity | |
print_r($result); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment