5 && strtolower(substr($url,0,5)) == "https" ) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } if (is_array($postFields) && count($postFields) > 0) { $postBodyString = ""; foreach ($postFields as $k => $v) { $postBodyString .= "$k=" . urlencode($v) . "&"; } unset($k, $v); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($postBodyString)); } $reponse = curl_exec($ch); if (curl_errno($ch)) { throw new Exception(curl_error($ch),0); } else { $http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (200 !== $http_status_code) { throw new Exception($reponse,$http_status_code); } } curl_close($ch); return $reponse; } /** * http请求 * @param $url * @param null $postFields * @return string * @throws Exception */ protected static function get_request($url,$postFields = null){ try{ $context = array("http"=>array("header"=>"Content-Type:application/x-www-form-urlencoded; charset=utf-8;".EOL)); if(isset(self::$read_timeout)){ $context["http"]["timeout"] = self::$read_timeout; } if (is_array($postFields) && count($postFields) > 0){ $query_params = http_build_query($postFields,"","&"); $context["http"]["method"] = "POST"; $context["http"]["content"] = $query_params; $context["http"]["header"] .= "Content-Length:".strlen($query_params).EOL; }else{ $context["http"]["method"] = "GET"; } return file_get_contents($url, false, stream_context_create($context)); }catch (Exception $e){ throw $e; } } }