📄 httpclient.java
字号:
/* * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v 1.98 2004/10/07 16:14:15 olegk Exp $ * $Revision: 509577 $ * $Date: 2007-02-20 15:28:18 +0100 (Tue, 20 Feb 2007) $ * * ==================================================================== * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */package org.apache.commons.httpclient;import java.io.IOException;import java.security.Provider;import java.security.Security;import org.apache.commons.httpclient.params.HttpClientParams;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * <p> * An HTTP "user-agent", containing an {@link HttpState HTTP state} and * one or more {@link HttpConnection HTTP connections}, to which * {@link HttpMethod HTTP methods} can be applied. * </p> * @author <a href="mailto:remm@apache.org">Remy Maucherat</a> * @author <a href="mailto:rwaldhoff@apache.org">Rodney Waldhoff</a> * @author Sean C. Sullivan * @author <a href="mailto:dion@apache.org">dIon Gillard</a> * @author Ortwin Gl?ck * @author <a href="mailto:becke@u.washington.edu">Michael Becke</a> * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> * @author Sam Maloney * @author Laura Werner * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a> * * @version $Revision: 509577 $ $Date: 2007-02-20 15:28:18 +0100 (Tue, 20 Feb 2007) $ */public class HttpClient { // -------------------------------------------------------------- Constants /** Log object for this class. */ private static final Log LOG = LogFactory.getLog(HttpClient.class); static { if (LOG.isDebugEnabled()) { try { LOG.debug("Java version: " + System.getProperty("java.version")); LOG.debug("Java vendor: " + System.getProperty("java.vendor")); LOG.debug("Java class path: " + System.getProperty("java.class.path")); LOG.debug("Operating system name: " + System.getProperty("os.name")); LOG.debug("Operating system architecture: " + System.getProperty("os.arch")); LOG.debug("Operating system version: " + System.getProperty("os.version")); Provider[] providers = Security.getProviders(); for (int i = 0; i < providers.length; i++) { Provider provider = providers[i]; LOG.debug(provider.getName() + " " + provider.getVersion() + ": " + provider.getInfo()); } } catch (SecurityException ignore) { } } } // ----------------------------------------------------------- Constructors /** * Creates an instance of HttpClient using default {@link HttpClientParams parameter set}. * * @see HttpClientParams */ public HttpClient() { this(new HttpClientParams()); } /** * Creates an instance of HttpClient using the given * {@link HttpClientParams parameter set}. * * @param params The {@link HttpClientParams parameters} to use. * * @see HttpClientParams * * @since 3.0 */ public HttpClient(HttpClientParams params) { super(); if (params == null) { throw new IllegalArgumentException("Params may not be null"); } this.params = params; this.httpConnectionManager = null; Class clazz = params.getConnectionManagerClass(); if (clazz != null) { try { this.httpConnectionManager = (HttpConnectionManager) clazz.newInstance(); } catch (Exception e) { LOG.warn("Error instantiating connection manager class, defaulting to" + " SimpleHttpConnectionManager", e); } } if (this.httpConnectionManager == null) { this.httpConnectionManager = new SimpleHttpConnectionManager(); } if (this.httpConnectionManager != null) { this.httpConnectionManager.getParams().setDefaults(this.params); } } /** * Creates an instance of HttpClient with a user specified * {@link HttpClientParams parameter set} and * {@link HttpConnectionManager HTTP connection manager}. * * @param params The {@link HttpClientParams parameters} to use. * @param httpConnectionManager The {@link HttpConnectionManager connection manager} * to use. * * @since 3.0 */ public HttpClient(HttpClientParams params, HttpConnectionManager httpConnectionManager) { super(); if (httpConnectionManager == null) { throw new IllegalArgumentException("httpConnectionManager cannot be null"); } if (params == null) { throw new IllegalArgumentException("Params may not be null"); } this.params = params; this.httpConnectionManager = httpConnectionManager; this.httpConnectionManager.getParams().setDefaults(this.params); } /** * Creates an instance of HttpClient with a user specified * {@link HttpConnectionManager HTTP connection manager}. * * @param httpConnectionManager The {@link HttpConnectionManager connection manager} * to use. * * @since 2.0 */ public HttpClient(HttpConnectionManager httpConnectionManager) { this(new HttpClientParams(), httpConnectionManager); } // ----------------------------------------------------- Instance Variables /** * The {@link HttpConnectionManager connection manager} being used to manage * connections for this HttpClient */ private HttpConnectionManager httpConnectionManager; /** * The {@link HttpState HTTP state} associated with this HttpClient. */ private HttpState state = new HttpState(); /** * The {@link HttpClientParams collection of parameters} associated with this HttpClient. */ private HttpClientParams params = null; /** * The {@link HostConfiguration host configuration} associated with * the HttpClient */ private HostConfiguration hostConfiguration = new HostConfiguration(); // ------------------------------------------------------------- Properties /** * Returns {@link HttpState HTTP state} associated with the HttpClient. * * @see #setState(HttpState) * @return the shared client state */ public synchronized HttpState getState() { return state; } /** * Assigns {@link HttpState HTTP state} for the HttpClient. * * @see #getState() * @param state the new {@link HttpState HTTP state} for the client */ public synchronized void setState(HttpState state) { this.state = state; } /** * Defines how strictly the method follows the HTTP protocol specification * (see RFC 2616 and other relevant RFCs). * * In the strict mode the method precisely * implements the requirements of the specification, whereas in non-strict mode * it attempts to mimic the exact behaviour of commonly used HTTP agents, * which many HTTP servers expect. * * @param strictMode <tt>true</tt> for strict mode, <tt>false</tt> otherwise * * @see #isStrictMode() * * @deprecated Use {@link HttpClientParams#setParameter(String, Object)} * to exercise a more granular control over HTTP protocol strictness. */ public synchronized void setStrictMode(boolean strictMode) { if (strictMode) { this.params.makeStrict(); } else { this.params.makeLenient(); } } /** * Returns the value of the strict mode flag. * * @return <tt>true</tt> if strict mode is enabled, <tt>false</tt> otherwise * * @see #setStrictMode(boolean) * * @deprecated Use * {@link org.apache.commons.httpclient.params.HttpClientParams#getParameter(String)} * to exercise a more granular control over HTTP protocol strictness. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -