1.post
public function getClassInfo($user_id, $token)
{
include(APPPATH."config/config.php");
$pPostData = Array();
$pPostData["token"] = $token;
$pPostData["user_id"] = $user_id;
$myurl = $config["api_esmart_get_class_info"];
//跨域訪問測試(使用CURL)
$ch = curl_init() ;
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL,$myurl) ;
$headers = array(
"Cache-Control: no-cache",
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //不使用緩存
curl_setopt($ch, CURLOPT_POST,count($pPostData)) ; // 启用时会发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。
curl_setopt($ch, CURLOPT_POSTFIELDS,$pPostData); // 在HTTP中的“POST”操作。如果要传送一个文件,需要一个@开头的文件名
ob_start();
curl_exec($ch);
$result = ob_get_contents() ;
ob_end_clean();
//close connection
curl_close($ch) ;
return $result;
}
2.get
public function getStudentList($pSchoolID, $pYearID, $pGradeID, $pClazzID, $pOffset, $pPageSize)
{
include(APPPATH."config/config.php");
$myurl = sprintf($config["api_getstudentlist"],$pSchoolID,$pYearID,$pGradeID,$pClazzID,$pOffset,$pPageSize);
//跨域訪問測試(使用CURL)
$ch = curl_init($myurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回
$headers = array(
"Cache-Control: no-cache",
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //不使用緩存
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
$output = curl_exec($ch) ;
return $output;
}