示例#1
0
        /**
         * Initializes the connection.
         */
        protected bool init(Env env)

        {
            if (!super.init(env))
            {
                return(false);
            }

            _body = PostBody.create(env, getCurlResource());

            if (_body == null)
            {
                return(false);
            }

            CurlHttpConnection conn = getHttpConnection();

            if (conn.getRequestProperty("Content-Type") == null)
            {
                conn.setRequestProperty("Content-Type",
                                        _body.getContentType());
            }

            if (conn.getRequestProperty("Content-Length") == null)
            {
                long contentLength = _body.getContentLength();

                if (contentLength >= 0)
                {
                    conn.setRequestProperty("Content-Length",
                                            String.valueOf(contentLength));
                }
                else if (false && _body.isChunked())
                {
                    conn.setRequestProperty("Transfer-Encoding", "chunked");
                }
            }

            conn.setDoOutput(true);

            return(true);
        }
        /**
         * Initializes the connection.
         */
        protected bool init(Env env)

        {
            if (_conn == null || _curl == null)
            {
                return(false);
            }

            if (!"GET".equals(_curl.getRequestMethod()))
            {
                _conn.setRequestMethod(_curl.getRequestMethod());
            }

            HashMap <String, String> _properties = _curl.getRequestPropertiesMap();

            for (Map.Entry <String, String> entry : _properties.entrySet())
            {
                _conn.setRequestProperty(entry.getKey(), entry.getValue());
            }

            _conn.setInstanceFollowRedirects(_curl.getIsFollowingRedirects());

            int timeout = _curl.getConnectTimeout();

            if (timeout >= 0)
            {
                _conn.setConnectTimeout(timeout);
            }

            timeout = _curl.getReadTimeout();
            if (timeout >= 0)
            {
                _conn.setReadTimeout(timeout);
            }

            return(true);
        }