Created
March 14, 2012 06:50
-
-
Save spin6lock/2034722 to your computer and use it in GitHub Desktop.
php curl api example
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 | |
$local = True; | |
$raw_data_public = 'data={"area":"0505u", "big_area":"1","net":"telcom", "view_type":1}'; | |
$raw_data_local = 'data={"area":"八月十五", "big_area":"广东区","net":"telcom", "view_type":1}'; | |
$url_public = 'http://c40.txsj.0505u.com:8080/gmapi/channel/'; | |
$url_local = 'http://219.136.138.172:8080/gmapi/channel/'; | |
if ($local){ | |
$data = base64_encode($raw_data_local); | |
$url = $url_local; | |
} | |
else{ | |
$data = base64_encode($raw_data_public); | |
$url = $url_public; | |
} | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
$text = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
var_dump($text); | |
var_dump(base64_decode($text)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment