程序员人生 网站导航

>>fun:httpPost/httpGET>>功能:向$url POST/GET 数据

栏目:php教程时间:2015-08-06 09:53:40

>>>函数名: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; }




------分隔线----------------------------
------分隔线----------------------------

最新技术推荐