用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > php教程

常用的curl发包函数

时间:2015-01-23  来源:西部数据  作者:西部数据
  1. function curl($url$postFields = null)   
  2.     {   
  3.         $ch = curl_init();   
  4.         curl_setopt($ch, CURLOPT_URL, $url);   
  5.         curl_setopt($ch, CURLOPT_FAILONERROR, false);   
  6.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
  7.    
  8.         if (is_array($postFields) && 0 < count($postFields))   
  9.         {   
  10.             $postBodyString = "";   
  11.             foreach ($postFields as $k => $v)   
  12.             {   
  13.                 $postBodyString .= "$k=" . urlencode($v) . "&";    
  14.             }   
  15.             unset($k$v);   
  16.             curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);     
  17.             curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);    
  18.             curl_setopt($ch, CURLOPT_POST, true);   
  19.             curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));   
  20.         }   
  21.         $reponse = curl_exec($ch);   
  22.         if (curl_errno($ch)){   
  23.             //throw new Exception(curl_error($ch),0);   
  24.             ShowMsg("授权出错,请联系管理员","/");   
  25.             exit();   
  26.         }   
  27.         else{   
  28.             $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);   
  29.             if (200 !== $httpStatusCode){   
  30.                 //throw new Exception($reponse,$httpStatusCode);   
  31.                 ShowMsg("授权出错,请联系管理员","/");   
  32.                 exit();   //phpfensi.com 
  33.             }   
  34.         }   
  35.         curl_close($ch);   
  36.         return $reponse;   
  37.     }
来顶一下
返回首页
返回首页
推荐资讯
WiFi太不安全:7岁女孩11分钟内入侵公共网络 WiFi太不安全:7岁女孩11分钟内入侵近期刚刚发布研究说WiFi网络能获得人们手机里多少私人信息,
不服跑个分?人工智能也出现“刷分”乱象 不服跑个分?人工智能也出现“刷分2014年,人工智能领域突然爆发,成为了科研和科技创业的热门
相关文章
    无相关信息
栏目更新
栏目热门