background image

        } 
 
        $method = strtolower($method); 
        if ('post' == $method) 
        { 
            curl_setopt($ch, CURLOPT_POST, true); 
            if (is_array($fields)) 
            { 
                $sets = array(); 
                foreach ($fields AS $key => $val) 
                { 
                    $sets[] = $key . '=' . urlencode($val); 
                } 
                $fields = implode('&',$sets); 
            } 
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
        } 
        else if ('put' == $method) 
        { 
            curl_setopt($ch, CURLOPT_PUT, true); 
        } 
 
        //curl_setopt($ch, CURLOPT_PROGRESS, true); 
        //curl_setopt($ch, CURLOPT_VERBOSE, true); 
        //curl_setopt($ch, CURLOPT_MUTE, false); 
        curl_setopt($ch, CURLOPT_TIMEOUT, 3);//设置 curl 超时秒数,例如将信息 POST 出去
3 秒钟后自动结束运行。 
 
        if (strlen($userAgent)) 
        { 
            curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); 
        } 
 
        if (is_array($httpHeaders)) 
        {  
            curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); 
        } 
 
        $ret = curl_exec($ch); 
 
        if (curl_errno($ch)) 
        { 
            curl_close($ch); 
            return array(curl_error($ch), curl_errno($ch));