zoukankan      html  css  js  c++  java
  • curl扩展代码

    
    /**
         * 
         * curl 支持post
         * @param string $base_url 基础链接
         * @param array $query_data 需要请求的数据
         * @param string $method 方法 get/post
         * @param boolean $ssl 关闭ssl验证
         * @param integer $exe_timeout 执行超时时间
         * @param integer $conn_timeout 连接超时时间
         * @param integer $dns_timeout dns超时时间
         */
        function tx_curl($base_url, $query_data, $method = 'get', $ssl = true, $exe_timeout = 10, $conn_timeout = 10, $dns_timeout = 3600)
        {
            $ch = curl_init();
            
            if ( $method == 'get' ) {
                //method get
                if ( ( !empty($query_data) )
                    && ( is_array($query_data) )
                ){
                    $connect_symbol = (strpos($base_url, '?')) ? '&' : '?';
                    foreach($query_data as $key => $val) {
                        if ( is_array($val) ) {
                            $val = serialize($val);
                        }
                        $base_url .= $connect_symbol . $key . '=' . rawurlencode($val);
                        $connect_symbol = '&';
                    }
                }
            } else {
                if ( ( !empty($query_data) )
                    && ( is_array($query_data) )
                ){
                    foreach($query_data as $key => $val) {
                        if ( is_array($val) ) {
                            $query_data[$key] = serialize($val);
                        }
                    }
                }
                //method post
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $query_data);
            }
            curl_setopt($ch, CURLOPT_URL, $base_url);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $conn_timeout);
            curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, $dns_timeout);
            curl_setopt($ch, CURLOPT_TIMEOUT, $exe_timeout);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            // 关闭ssl验证
            if($ssl){
            	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            }
    
            $output = curl_exec($ch);
            
            if ( $output === FALSE )
                $output = '';
                
            curl_close($ch);
            return $output;
        }
    
    
  • 相关阅读:
    xavier NX编译caffe错误记录(二)
    ubuntu16安装微信
    linux中安装onenote(P3X OneNote)
    ubuntu16中,google浏览器安装OneNote Web Clipper插件
    酒店门锁接口说明
    在xaf 14 中实现 Tonyyang原文中的action权限
    MRP生产计划模式在多品种小批量生产过程中遭遇挑战
    C#代码
    简陋的会计凭证金额输入控件(加强) [转]
    简陋的会计凭证金额输入控件(再加强) [转]
  • 原文地址:https://www.cnblogs.com/qixidi/p/10206154.html
Copyright © 2011-2022 走看看