加入收藏 | 设为首页 | 会员中心 | 我要投稿 吉安站长网 (https://www.0796zz.com.cn/)- 科技、图像处理、媒体智能、办公协同、操作系统!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

常用的curl发包函数

发布时间:2022-07-29 10:56:49 所属栏目:PHP教程 来源:互联网
导读:function curl($url, $postFields = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if (is_array($postFields) 0 count($postFields))
  function curl($url, $postFields = null)   
      {   
          $ch = curl_init();   
          curl_setopt($ch, CURLOPT_URL, $url);   
          curl_setopt($ch, CURLOPT_FAILONERROR, false);   
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
     
          if (is_array($postFields) && 0 < count($postFields))   
          {   
              $postBodyString = "";   
              foreach ($postFields as $k => $v)   
              {   
                  $postBodyString .= "$k=" . urlencode($v) . "&";    
              }   
              unset($k, $v);   
              curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);     
              curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);    
              curl_setopt($ch, CURLOPT_POST, true);   
              curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));   
          }   
          $reponse = curl_exec($ch);   
          if (curl_errno($ch)){   
              //throw new Exception(curl_error($ch),0);   
              ShowMsg("授权出错,请联系管理员","/");   
              exit();   
          }   
          else{   
              $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);   
              if (200 !== $httpStatusCode){   
                  //throw new Exception($reponse,$httpStatusCode);   
                  ShowMsg("授权出错,请联系管理员","/");   
                  exit();   //phpfensi.com
              }   
          }   
          curl_close($ch);   
          return $reponse;   
      }

(编辑:吉安站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读