>>fun:httpPost/httpGET>>功能:向$url POST/GET 数据
>>>函数名: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; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。