コード例 #1
0
ファイル: functions.php プロジェクト: xxf1995/alphaV
 function class_http($url, $params = array())
 {
     if ($params['http']) {
         $class = 'WP_Http_' . ucfirst($params['http']);
     } else {
         if (!close_curl()) {
             $class = 'WP_Http_Curl';
         } else {
             http_ssl($url);
             if (@ini_get('allow_url_fopen') && function_exists('fopen')) {
                 $class = 'WP_Http_Streams';
             } elseif (function_exists('fsockopen')) {
                 $class = 'WP_Http_Fsockopen';
             } else {
                 return wp_die('没有可以完成请求的 HTTP 传输器,请查看<a href="' . MY_PLUGIN_URL . '/check.php" target="_blank">环境检查</a>');
             }
         }
     }
     $http = new $class();
     $response = $http->request($url, $params);
     if (!is_array($response)) {
         if ($params['method'] == 'GET' && @ini_get('allow_url_fopen') && function_exists('file_get_contents')) {
             return file_get_contents($url . '?' . $params['body']);
         }
         $errors = $response->errors;
         $error = $errors['http_request_failed'][0];
         if (!$error) {
             $error = $errors['http_failure'][0];
         }
         if ($error == "couldn't connect to host" || strpos($error, 'timed out') !== false) {
             return;
         }
         wp_die('出错了: ' . $error . '<br /><br />可能是您的主机不支持,请查看<a href="' . MY_PLUGIN_URL . '/check.php" target="_blank">环境检查</a>');
     }
     return $response['body'];
 }
コード例 #2
0
function class_http($url, $params = array())
{
    if ($params['http']) {
        $class = 'WP_Http_' . ucfirst($params['http']);
    } else {
        if (!close_curl()) {
            $class = 'WP_Http_Curl';
        } else {
            http_ssl($url);
            if (@ini_get('allow_url_fopen') && function_exists('fopen')) {
                $class = 'WP_Http_Streams';
            } elseif (function_exists('fsockopen')) {
                $class = 'WP_Http_Fsockopen';
            } else {
                return wp_die('没有可以完成请求的 HTTP 传输器,请查看<a href="' . MY_PLUGIN_URL . '/check.php">环境检查</a>');
            }
        }
    }
    $http = new $class();
    $response = $http->request($url, $params);
    if (!is_array($response)) {
        $errors = $response->errors;
        $error = $errors['http_request_failed'][0];
        if (!$error) {
            $error = $errors['http_failure'][0];
        }
        wp_die('出错了: ' . $error . '<br /><br />可能是您的主机不支持,请查看<a href="' . MY_PLUGIN_URL . '/check.php">环境检查</a>');
    }
    return $response['body'];
}