>>>函数名:httpPost
功能:向$url POST xml数据
code:
/** * [httpPost 向$url POST $data数据] * @param [sting] $url [action url] * @param [array] $data [数据数组 eg:$data = <xml><user>root</user><pwd>ooxx</pwd></xml>] * @return [sting] $res [响应数据] */ function httpPost($url,$data){ //定义content-type为xml,注意是数组 $header[] = "Content-type:text/xml"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_TIMEOUT, 500); //防止出现验证错误 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $res = curl_exec($ch); if(curl_errno($ch)){ print curl_error($ch); } curl_close($ch); return $res; }
>>>函数名:httpGet
功能:向$url POST $data数据
code:
/** * [httpGet get $url 返回的数据] * @param [sting] $url [目标url] * @return [sting] $res [响应数据] */ function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); $res = curl_exec($curl); curl_close($curl); return $res; }
时间: 2024-10-25 13:10:44