<?phpfunction dcurl($url, $method = ‘GET‘, $postFields = null, $header = null) { ???$ch = curl_init(); ???curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); ???curl_setopt($ch, CURLOPT_FAILONERROR, false); ???curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); ???curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); ???curl_setopt($ch, CURLOPT_TIMEOUT, 5); ???if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") ???{ ???????curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); ???????curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); ???} ???switch ($method) ???{ ???????case ‘POST‘: ???????????curl_setopt($ch, CURLOPT_POST, true); ???????????if (!empty($postFields)) ???????????{ ???????????????if (is_array($postFields) || is_object($postFields)) ???????????????{ ???????????????????if (is_object($postFields)) ???????????????????????$postFields = Tools::object2array($postFields); ???????????????????$postBodyString = ""; ???????????????????$postMultipart = false; ???????????????????foreach ($postFields as $k => $v) ???????????????????{ ???????????????????????if ("@" != substr($v, 0, 1)) ???????????????????????{ //判断是不是文件上传 ???????????????????????????$postBodyString .= "$k=" . urlencode($v) . "&"; ???????????????????????} ???????????????????????else ???????????????????????{ //文件上传用multipart/form-data,否则用www-form-urlencoded ???????????????????????????$postMultipart = true; ???????????????????????} ???????????????????} ???????????????????unset($k, $v); ???????????????????if ($postMultipart) ???????????????????{ ???????????????????????curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); ???????????????????} ???????????????????else ???????????????????{ ???????????????????????curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1)); ???????????????????} ???????????????} ???????????????else ???????????????{ ???????????????????curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); ???????????????} ???????????} ???????????break; ???????default: ???????????if (!empty($postFields) && is_array($postFields)) ???????????????$url .= (strpos($url, ‘?‘) === false ? ‘?‘ : ‘&‘) . http_build_query($postFields); ???????????break; ???}}?>
;
php自定义函数: 改进升级版curl
原文地址:http://www.cnblogs.com/upup2015/p/7786801.html