📄 httpclient.java
字号:
public synchronized boolean isStrictMode() { return false; } /** * Sets the socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the * timeout for waiting for data. A timeout value of zero is interpreted as an * infinite timeout. * * @param newTimeoutInMilliseconds Timeout in milliseconds * * @deprecated Use * {@link org.apache.commons.httpclient.params.HttpConnectionManagerParams#setSoTimeout(int)}, * {@link HttpConnectionManager#getParams()}. * */ public synchronized void setTimeout(int newTimeoutInMilliseconds) { this.params.setSoTimeout(newTimeoutInMilliseconds); } /** * Sets the timeout in milliseconds used when retrieving an * {@link HttpConnection HTTP connection} from the * {@link HttpConnectionManager HTTP connection manager}. * * @param timeout the timeout in milliseconds * * @see HttpConnectionManager#getConnection(HostConfiguration, long) * * @deprecated Use * {@link org.apache.commons.httpclient.params.HttpClientParams#setConnectionManagerTimeout(long)}, * {@link HttpClient#getParams()} */ public synchronized void setHttpConnectionFactoryTimeout(long timeout) { this.params.setConnectionManagerTimeout(timeout); } /** * Sets the timeout until a connection is etablished. A value of zero * means the timeout is not used. The default value is zero. * * @see HttpConnection#setConnectionTimeout(int) * @param newTimeoutInMilliseconds Timeout in milliseconds. * * @deprecated Use * {@link org.apache.commons.httpclient.params.HttpConnectionManagerParams#setConnectionTimeout(int)}, * {@link HttpConnectionManager#getParams()}. */ public synchronized void setConnectionTimeout(int newTimeoutInMilliseconds) { this.httpConnectionManager.getParams().setConnectionTimeout(newTimeoutInMilliseconds); } // --------------------------------------------------------- Public Methods /** * Executes the given {@link HttpMethod HTTP method}. * * @param method the {@link HttpMethod HTTP method} to execute. * @return the method's response code * * @throws IOException If an I/O (transport) error occurs. Some transport exceptions * can be recovered from. * @throws HttpException If a protocol exception occurs. Usually protocol exceptions * cannot be recovered from. */ public int executeMethod(HttpMethod method) throws IOException, HttpException { LOG.trace("enter HttpClient.executeMethod(HttpMethod)"); // execute this method and use its host configuration, if it has one return executeMethod(null, method, null); } /** * Executes the given {@link HttpMethod HTTP method} using custom * {@link HostConfiguration host configuration}. * * @param hostConfiguration The {@link HostConfiguration host configuration} to use. * If <code>null</code>, the host configuration returned by {@link #getHostConfiguration} will be used. * @param method the {@link HttpMethod HTTP method} to execute. * @return the method's response code * * @throws IOException If an I/O (transport) error occurs. Some transport exceptions * can be recovered from. * @throws HttpException If a protocol exception occurs. Usually protocol exceptions * cannot be recovered from. * @since 2.0 */ public int executeMethod(final HostConfiguration hostConfiguration, final HttpMethod method) throws IOException, HttpException { LOG.trace("enter HttpClient.executeMethod(HostConfiguration,HttpMethod)"); return executeMethod(hostConfiguration, method, null); } /** * Executes the given {@link HttpMethod HTTP method} using the given custom * {@link HostConfiguration host configuration} with the given custom * {@link HttpState HTTP state}. * * @param hostconfig The {@link HostConfiguration host configuration} to use. * If <code>null</code>, the host configuration returned by {@link #getHostConfiguration} will be used. * @param method the {@link HttpMethod HTTP method} to execute. * @param state the {@link HttpState HTTP state} to use when executing the method. * If <code>null</code>, the state returned by {@link #getState} will be used. * * @return the method's response code * * @throws IOException If an I/O (transport) error occurs. Some transport exceptions * can be recovered from. * @throws HttpException If a protocol exception occurs. Usually protocol exceptions * cannot be recovered from. * @since 2.0 */ public int executeMethod(HostConfiguration hostconfig, final HttpMethod method, final HttpState state) throws IOException, HttpException { LOG.trace("enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)"); if (method == null) { throw new IllegalArgumentException("HttpMethod parameter may not be null"); } HostConfiguration defaulthostconfig = getHostConfiguration(); if (hostconfig == null) { hostconfig = defaulthostconfig; } URI uri = method.getURI(); if (hostconfig == defaulthostconfig || uri.isAbsoluteURI()) { // make a deep copy of the host defaults hostconfig = (HostConfiguration) hostconfig.clone(); if (uri.isAbsoluteURI()) { hostconfig.setHost(uri); } } HttpMethodDirector methodDirector = new HttpMethodDirector( getHttpConnectionManager(), hostconfig, this.params, (state == null ? getState() : state)); methodDirector.executeMethod(method); return method.getStatusCode(); } /** * Returns the default host. * * @return The default host. * * @deprecated use #getHostConfiguration() */ public String getHost() { return hostConfiguration.getHost(); } /** * Returns the default port. * * @return The default port. * * @deprecated use #getHostConfiguration() */ public int getPort() { return hostConfiguration.getPort(); } /** * Returns the {@link HostConfiguration host configuration} associated with the * HttpClient. * * @return {@link HostConfiguration host configuration} * * @since 2.0 */ public synchronized HostConfiguration getHostConfiguration() { return hostConfiguration; } /** * Assigns the {@link HostConfiguration host configuration} to use with the * HttpClient. * * @param hostConfiguration The {@link HostConfiguration host configuration} to set * * @since 2.0 */ public synchronized void setHostConfiguration(HostConfiguration hostConfiguration) { this.hostConfiguration = hostConfiguration; } /** * Returns the {@link HttpConnectionManager HTTP connection manager} associated * with the HttpClient. * * @return {@link HttpConnectionManager HTTP connection manager} * * @since 2.0 */ public synchronized HttpConnectionManager getHttpConnectionManager() { return httpConnectionManager; } /** * Assigns the {@link HttpConnectionManager HTTP connection manager} to use with * the HttpClient. * * @param httpConnectionManager The {@link HttpConnectionManager HTTP connection manager} * to set * * @since 2.0 */ public synchronized void setHttpConnectionManager( HttpConnectionManager httpConnectionManager ) { this.httpConnectionManager = httpConnectionManager; if (this.httpConnectionManager != null) { this.httpConnectionManager.getParams().setDefaults(this.params); } } /** * Returns {@link HttpClientParams HTTP protocol parameters} associated with this HttpClient. * * @since 3.0 * * @see HttpClientParams */ public HttpClientParams getParams() { return this.params; } /** * Assigns {@link HttpClientParams HTTP protocol parameters} for this HttpClient. * * @since 3.0 * * @see HttpClientParams */ public void setParams(final HttpClientParams params) { if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); } this.params = params; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -