⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.php

📁 希望此段源编码能给所有需要它的朋友带去快乐
💻 PHP
📖 第 1 页 / 共 3 页
字号:
     * @return string|array|null The header value or null if it is not set     */    public function getHeader($key)    {        $key = strtolower($key);        if (isset($this->headers[$key])) {            return $this->headers[$key][1];        } else {            return null;        }    }    /**     * Set a GET parameter for the request. Wrapper around _setParameter     *     * @param string|array $name     * @param string $value     * @return Zend_Http_Client     */    public function setParameterGet($name, $value = null)    {        if (is_array($name)) {            foreach ($name as $k => $v)                $this->_setParameter('GET', $k, $v);        } else {            $this->_setParameter('GET', $name, $value);        }        return $this;    }    /**     * Set a POST parameter for the request. Wrapper around _setParameter     *     * @param string|array $name     * @param string $value     * @return Zend_Http_Client     */    public function setParameterPost($name, $value = null)    {        if (is_array($name)) {            foreach ($name as $k => $v)                $this->_setParameter('POST', $k, $v);        } else {            $this->_setParameter('POST', $name, $value);        }        return $this;    }    /**     * Set a GET or POST parameter - used by SetParameterGet and SetParameterPost     *     * @param string $type GET or POST     * @param string $name     * @param string $value     */    protected function _setParameter($type, $name, $value)    {        $parray = array();        $type = strtolower($type);        switch ($type) {            case 'get':                $parray = &$this->paramsGet;                break;            case 'post':                $parray = &$this->paramsPost;                break;        }        if ($value === null) {            if (isset($parray[$name])) unset($parray[$name]);        } else {            $parray[$name] = $value;        }    }    /**     * Get the number of redirections done on the last request     *     * @return int     */    public function getRedirectionsCount()    {        return $this->redirectCounter;    }    /**     * Set HTTP authentication parameters     *     * $type should be one of the supported types - see the self::AUTH_*     * constants.     *     * To enable authentication:     * <code>     * $this->setAuth('shahar', 'secret', Zend_Http_Client::AUTH_BASIC);     * </code>     *     * To disable authentication:     * <code>     * $this->setAuth(false);     * </code>     *     * @see http://www.faqs.org/rfcs/rfc2617.html     * @param string|false $user User name or false disable authentication     * @param string $password Password     * @param string $type Authentication type     * @return Zend_Http_Client     */    public function setAuth($user, $password = '', $type = self::AUTH_BASIC)    {        // If we got false or null, disable authentication        if ($user === false || $user === null) {            $this->auth = null;        // Else, set up authentication        } else {            // Check we got a proper authentication type            if (! defined('self::AUTH_' . strtoupper($type))) {                require_once 'Zend/Http/Client/Exception.php';                throw new Zend_Http_Client_Exception("Invalid or not supported authentication type: '$type'");            }            $this->auth = array(                'user' => (string) $user,                'password' => (string) $password,                'type' => $type            );        }        return $this;    }    /**     * Set the HTTP client's cookie jar.     *     * A cookie jar is an object that holds and maintains cookies across HTTP requests     * and responses.     *     * @param Zend_Http_CookieJar|boolean $cookiejar Existing cookiejar object, true to create a new one, false to disable     * @return Zend_Http_Client     */    public function setCookieJar($cookiejar = true)    {        if (! class_exists('Zend_Http_CookieJar'))            require_once 'Zend/Http/CookieJar.php';        if ($cookiejar instanceof Zend_Http_CookieJar) {            $this->cookiejar = $cookiejar;        } elseif ($cookiejar === true) {            $this->cookiejar = new Zend_Http_CookieJar();        } elseif (! $cookiejar) {            $this->cookiejar = null;        } else {            require_once 'Zend/Http/Client/Exception.php';            throw new Zend_Http_Client_Exception('Invalid parameter type passed as CookieJar');        }        return $this;    }    /**     * Return the current cookie jar or null if none.     *     * @return Zend_Http_CookieJar|null     */    public function getCookieJar()    {        return $this->cookiejar;    }    /**     * Add a cookie to the request. If the client has no Cookie Jar, the cookies     * will be added directly to the headers array as "Cookie" headers.     *     * @param Zend_Http_Cookie|string $cookie     * @param string|null $value If "cookie" is a string, this is the cookie value.     * @return Zend_Http_Client     */    public function setCookie($cookie, $value = null)    {        if (! class_exists('Zend_Http_Cookie'))            require_once 'Zend/Http/Cookie.php';        if (is_array($cookie)) {            foreach ($cookie as $c => $v) {                if (is_string($c)) {                    $this->setCookie($c, $v);                } else {                    $this->setCookie($v);                }            }            return $this;        }        if ($value !== null) $value = urlencode($value);        if (isset($this->cookiejar)) {            if ($cookie instanceof Zend_Http_Cookie) {                $this->cookiejar->addCookie($cookie);            } elseif (is_string($cookie) && $value !== null) {                $cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}", $this->uri);                $this->cookiejar->addCookie($cookie);            }        } else {            if ($cookie instanceof Zend_Http_Cookie) {                $name = $cookie->getName();                $value = $cookie->getValue();                $cookie = $name;            }            if (preg_match("/[=,; \t\r\n\013\014]/", $cookie)) {                require_once 'Zend/Http/Client/Exception.php';                throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\013\014 ({$cookie})");            }            $value = addslashes($value);            if (! isset($this->headers['cookie'])) $this->headers['cookie'] = array('Cookie', '');            $this->headers['cookie'][1] .= $cookie . '=' . $value . '; ';        }        return $this;    }    /**     * Set a file to upload (using a POST request)     *     * Can be used in two ways:     *     * 1. $data is null (default): $filename is treated as the name if a local file which     *    will be read and sent. Will try to guess the content type using mime_content_type().     * 2. $data is set - $filename is sent as the file name, but $data is sent as the file     *    contents and no file is read from the file system. In this case, you need to     *    manually set the content-type ($ctype) or it will default to     *    application/octet-stream.     *     * @param string $filename Name of file to upload, or name to save as     * @param string $formname Name of form element to send as     * @param string $data Data to send (if null, $filename is read and sent)     * @param string $ctype Content type to use (if $data is set and $ctype is     *     null, will be application/octet-stream)     * @return Zend_Http_Client     */    public function setFileUpload($filename, $formname, $data = null, $ctype = null)    {        if ($data === null) {            if (($data = @file_get_contents($filename)) === false) {                require_once 'Zend/Http/Client/Exception.php';                throw new Zend_Http_Client_Exception("Unable to read file '{$filename}' for upload");            }            if (! $ctype && function_exists('mime_content_type')) $ctype = mime_content_type($filename);        }        // Force enctype to multipart/form-data        $this->setEncType(self::ENC_FORMDATA);        if ($ctype === null) $ctype = 'application/octet-stream';        $this->files[$formname] = array(basename($filename), $ctype, $data);        return $this;    }    /**     * Set the encoding type for POST data     *     * @param string $enctype     * @return Zend_Http_Client     */    public function setEncType($enctype = self::ENC_URLENCODED)    {        $this->enctype = $enctype;        return $this;    }    /**     * Set the raw (already encoded) POST data.     *     * This function is here for two reasons:     * 1. For advanced user who would like to set their own data, already encoded     * 2. For backwards compatibilty: If someone uses the old post($data) method.     *    this method will be used to set the encoded data.     *     * @param string $data     * @param string $enctype     * @return Zend_Http_Client     */    public function setRawData($data, $enctype = null)    {        $this->raw_post_data = $data;        $this->setEncType($enctype);        return $this;    }    /**     * Clear all GET and POST parameters     *     * Should be used to reset the request parameters if the client is     * used for several concurrent requests.     *     * @return Zend_Http_Client     */    public function resetParameters()    {        // Reset parameter data        $this->paramsGet     = array();        $this->paramsPost    = array();        $this->files         = array();        $this->raw_post_data = null;        // Clear outdated headers        if (isset($this->headers['content-type'])) unset($this->headers['content-type']);        if (isset($this->headers['content-length'])) unset($this->headers['content-length']);        return $this;    }    /**     * Get the last HTTP request as string     *     * @return string     */    public function getLastRequest()    {        return $this->last_request;    }    /**     * Get the last HTTP response received by this client     *     * If $config['storeresponse'] is set to false, or no response was     * stored yet, will return null     *     * @return Zend_Http_Response or null if none     */    public function getLastResponse()    {        return $this->last_response;    }    /**     * Load the connection adapter     *     * While this method is not called more than one for a client, it is     * seperated from ->request() to preserve logic and readability     *     * @param Zend_Http_Client_Adapter_Interface|string $adapter     */    public function setAdapter($adapter)    {        if (is_string($adapter)) {            try {                Zend_Loader::loadClass($adapter);            } catch (Zend_Exception $e) {                require_once 'Zend/Http/Client/Exception.php';                throw new Zend_Http_Client_Exception("Unable to load adapter '$adapter': {$e->getMessage()}");            }            $adapter = new $adapter;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -