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;
}