function httpRequest($url, $method, $params) { $args = array('method' => $method, 'timeout' => $this->timeout, 'redirection' => 5, 'httpversion' => '1.0', 'user-agent' => $this->userAgent, 'headers' => array('Expect' => ''), 'sslverify' => true); switch ($method) { case 'GET': $url .= '?' . http_build_query($params, null, '&'); // overwrite arg_separator.output break; case 'POST': $headers = array(); $args['body'] = http_build_query($params); break; default: } $http = new EasyHttp(); $response = $http->request($url, $args); if (isset($response->errors)) { if (isset($response->errors['http_request_failed'])) { $message = $response->errors['http_request_failed'][0]; if ($message == 'name lookup timed out') { $message = 'DNS解析超时,请重试或检查你的主机的域名解析(DNS)设置。'; } elseif (stripos($message, 'Could not open handle for fopen') === 0) { $message = '无法打开fopen句柄,请重试或联系多说管理员。http://dev.duoshuo.com/'; } elseif (stripos($message, 'Couldn\'t resolve host') === 0) { $message = '无法解析duoshuo.com域名,请重试或检查你的主机的域名解析(DNS)设置。'; } elseif (stripos($message, 'Operation timed out after ') === 0) { $message = '操作超时,请重试或联系多说管理员。http://dev.duoshuo.com/'; } throw new Duoshuo_Exception($message, Duoshuo_Exception::REQUEST_TIMED_OUT); } else { throw new Duoshuo_Exception('连接服务器失败, 详细信息:' . json_encode($response->errors), Duoshuo_Exception::REQUEST_TIMED_OUT); } } $json = json_decode($response['body'], true); return $json === null ? $response['body'] : $json; }
/** * Convert cookie name and value back to header string. * * @access public * @since 2.8.0 * * @return string Header encoded cookie name and value. */ function getHeaderValue() { if (empty($this->name) || empty($this->value)) { return ''; } return $this->name . '=' . EasyHttp::applyFilters('wp_http_cookie_value', $this->value, $this->name); }
/** * Whether this class can be used for retrieving an URL. * * @since 2.7.0 * @static * @return boolean False means this class can not be used, true means it can. */ public static function test($args = array()) { if (!function_exists('fsockopen')) { return false; } //不支持这个自动disable的功能 //if ( false !== ($option = EasyHttp::getOption( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours // return false; $is_ssl = isset($args['ssl']) && $args['ssl']; if ($is_ssl && !extension_loaded('openssl')) { return false; } return EasyHttp::applyFilters('use_fsockopen_transport', true, $args); }
/** * Navigates through an array and removes slashes from the values. * * If an array is passed, the array_map() function causes a callback to pass the * value back to the function. The slashes from this value will removed. * * @since 2.0.0 * * @param array|string $value The array or string to be stripped. * @return array|string Stripped array (or string in the callback). */ static function stripslashesDeep($value) { if (is_array($value)) { $value = array_map(array('EasyHttp', 'stripslashesDeep'), $value); } elseif (is_object($value)) { $vars = get_object_vars($value); foreach ($vars as $key => $data) { $value->{$key} = EasyHttp::stripslashesDeep($data); } } else { $value = stripslashes($value); } return $value; }
/** * Whether this class can be used for retrieving an URL. * * @static * @since 2.7.0 * * @return boolean False means this class can not be used, true means it can. */ public static function test($args = array()) { if (!function_exists('curl_init') || !function_exists('curl_exec')) { return false; } $is_ssl = isset($args['ssl']) && $args['ssl']; if ($is_ssl) { $curl_version = curl_version(); if (!(CURL_VERSION_SSL & $curl_version['features'])) { // Does this cURL version support SSL requests? return false; } } return EasyHttp::applyFilters('use_curl_transport', true, $args); }
/** * Whether this class can be used for retrieving an URL. * * @static * @access public * @since 2.7.0 * * @return boolean False means this class can not be used, true means it can. */ public static function test($args = array()) { if (!function_exists('fopen')) { return false; } if (!function_exists('ini_get') || true != ini_get('allow_url_fopen')) { return false; } $is_ssl = isset($args['ssl']) && $args['ssl']; if ($is_ssl && !extension_loaded('openssl')) { return false; } return EasyHttp::applyFilters('use_streams_transport', true, $args); }