Skip to content

Instantly share code, notes, and snippets.

@spin6lock
Created March 14, 2012 06:50
Show Gist options
  • Save spin6lock/2034722 to your computer and use it in GitHub Desktop.
Save spin6lock/2034722 to your computer and use it in GitHub Desktop.
php curl api example
<?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