`

HttpClient

 
阅读更多
一、httpclient相关项目的说明:
    The Commons HttpClient project is now end of life, and is no longer being
developed. It has been replaced by the Apache HttpComponents project in its
HttpClient and HttpCore modules, which offer better performance and more
flexibility.

二、使用httpclient的原因:
    Although the java.net package provides basic functionality for accessing resources via HTTP, it doesn't provide the full flexibility or functionality needed by many applications. The Jakarta Commons HttpClient component seeks to fill this void by providing an efficient, up-to-date, and feature-rich package implementing the client side of the most recent HTTP standards and recommendations. See the Features page for more details on standards compliance and capabilities.Designed for extension while providing robust support for the base HTTP protocol, the HttpClient component may be of interest to anyone building HTTP-aware client applications such as web browsers, web service clients, or systems that leverage or extend the HTTP protocol for distributed communication.
There are many projects that use HttpClient to provide the core HTTP functionality. Some of these are open source with project pages you can find on the web while others are closed source that you would never see or hear about. The Apache Source License provides maximum flexibility for source and binary reuse. Please see the Applications page for projects using HttpClient.

三、基本的使用例子:

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;

/**
* This example demonstrates how to abort an HTTP method before its normal completion.
*/
public class ClientAbortMethod {

    public final static void main(String[] args) throws Exception {
        HttpClient httpclient = new DefaultHttpClient();
        HttpHost proxy = new HttpHost("proxy.zte.com.cn", 80, "http");
        try {
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
       
            HttpGet httpget = new HttpGet("http://www.baidu.com/");

            System.out.println("executing request " + httpget.getURI());
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            InputStream in=entity.getContent();
            byte sss[]=new byte[5000];
            in.read(sss);
            FileOutputStream fo=new FileOutputStream(new File("c:/sshhshshs.txt"));
            fo.write(sss);
            System.out.println(new String(sss,"GB2312"));
            System.out.println("----------------------------------------");
            httpget.abort();
        } finally {

            httpclient.getConnectionManager().shutdown();
        }
    }
}

四、类说明:
1.包: org.apache.http.HttpHost
  类名:public final class HttpHost extends Object implements Cloneable,Serializable
   说明:Holds all of the variables needed to describe an HTTP connection to a host. This includes remote host name, port and scheme.

1)构造函数:HttpHost

public HttpHost(String hostname,
                int port,
                String scheme)
Creates a new HttpHost, specifying all values. Constructor for HttpHost.
Parameters:
hostname - the hostname (IP or DNS name)
port - the port number. -1 indicates the scheme default port.
scheme - the name of the scheme. null indicates the default scheme
该类是httpcomponents-core-4.1.4里面的类

2.包:org.apache.http.impl.client
  类:public class DefaultHttpClient
extends AbstractHttpClient
  说明:Default implementation of HttpClient pre-configured for most common use scenarios.

1)方法:getParams

public final HttpParams getParams()
Description copied from interface: HttpClient
Obtains the parameters for this client. These parameters will become defaults for
all requests being executed with this client, and for the parameters of dependent
objects in this client.
Specified by:
getParams in interface HttpClient
Returns:
the default parameters

3. 包:org.apache.http.params
   接口名:public interface HttpParams
   说明:HttpParams interface represents a collection of immutable values that define a runtime behavior of a component. HTTP parameters should be simple objects: integers, doubles, strings, collections and objects that remain immutable at runtime.

1)方法:setParameter

HttpParams setParameter(String name,
                        Object value)
Assigns the value to the parameter with the given name.
Parameters:
name - parameter name
value - parameter value

4.包:org.apache.http.conn.params.ConnRouteParams
  类名:public class ConnRouteParams extends Object implements ConnRoutePNames
  说明:An adaptor for manipulating HTTP routing parameters in HttpParams.
 
分享到:
评论

相关推荐

    httpclient.jar包下载

    《深入解析httpclient.jar及其与code.jar的关联》 在Java开发中,HTTP通信是不可或缺的一部分,而Apache HttpClient库正是Java实现HTTP客户端操作的重要工具。本文将深入探讨httpclient.jar包,以及它与code.jar包...

    HttpClient4.2.1版本的Jar包

    HttpClient 4.2.1版本引入了一些重要的改进和修复,以提高性能和稳定性。以下是一些关键特性: 1. **连接管理**:HttpClient 4.2.1引入了更完善的连接管理机制,允许开发者控制连接的创建、复用和关闭。`...

    HttpClient 3.x to HttpComponents HttpClient 4.x

    例如,在HttpClient 3.x中,代码可能会使用`***mons.httpclient.HttpClient`类和`***mons.httpclient.methods.GetMethod`等,而在4.x版本中,这些都被新的API所替代。程序员需要熟悉`org.apache....

    httpclient-4.2.5-API文档-中文版.zip

    赠送jar包:httpclient-4.2.5.jar; 赠送原API文档:httpclient-4.2.5-javadoc.jar; 赠送源代码:httpclient-4.2.5-sources.jar; 赠送Maven依赖信息文件:httpclient-4.2.5.pom; 包含翻译后的API文档:httpclient...

    httpclient4.2.1.zip

    本文将深入探讨HttpClient 4.2.1的核心特性和使用方法,帮助开发者更好地理解和应用这个强大的工具。 一、HttpClient简介 HttpClient是一个开放源码的Java库,由Apache软件基金会维护。它为Java程序员提供了一个...

    httpClient

    HttpClient httpClient = new HttpClient(); // 设置 Http 连接超时为5秒 httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); /* 2 生成 GetMethod 对象并设置参数 */ GetMethod ...

    httpclient-4.5.6-API文档-中文版.zip

    赠送jar包:httpclient-4.5.6.jar; 赠送原API文档:httpclient-4.5.6-javadoc.jar; 赠送源代码:httpclient-4.5.6-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.6.pom; 包含翻译后的API文档:httpclient...

    httpclient

    使用HttpClient发送请求、接收响应很简单,一般需要如下几步即可。 1. 创建HttpClient对象。 2. 创建请求方法的实例,并指定请求URL。如果需要发送GET请求,创建HttpGet对象;如果需要发送POST请求,创建...

    HttpClientHelper 工具类

    HttpClientHelper 对这个类进行了封装,使得开发者无需直接与HttpClient接口打交道,而是通过更简洁、易用的方法调用来实现网络通信。这提高了代码的可读性和可维护性。 单例模式是软件设计模式的一种,确保一个类...

    HttpClient所需jar包(全) httpClient.4.13jar

    HttpClient 4.13版本是这个库的一个较新版本,包含了一系列的改进和修复。 在Java开发中,HttpClient是一个常用的工具,尤其在处理Web服务或者API调用时。它支持同步和异步操作,可以处理复杂的HTTP协议细节,使...

    httpClient实例httpClient调用 http/https实例 忽略SSL验证

    这个实例主要涉及如何配置HttpClient来忽略SSL(Secure Socket Layer)验证,这对于在开发和测试环境中处理自签名证书或未认证的服务器非常有用。以下将详细介绍HttpClient的使用以及如何进行SSL验证的忽略。 首先...

    httpclient方式调用url

    本篇文章将深入探讨如何使用HttpClient方式调用URL,以及相关的知识点。 首先,HttpClient允许我们构建复杂的HTTP请求,包括GET、POST以及其他HTTP方法。使用HttpClient调用URL的基本步骤包括创建HttpClient实例、...

    httpClient需要的jar包

    本压缩包文件"httpClient"很可能包含了HttpClient库所需的必备JAR文件,这些文件通常包括HttpClient的核心库、依赖的第三方库以及可能的扩展模块。为了正确使用HttpClient,你需要确保将这些JAR文件添加到你的项目类...

    HttpClient 调用WebService示例

    在本文中,我们将深入探讨如何使用HttpClient调用WebService。 首先,调用WebService通常涉及SOAP(Simple Object Access Protocol)或RESTful API。HttpClient可以处理这两种类型的Web服务。在本示例中,我们假设...

    httpclient-4.5.5-API文档-中文版.zip

    赠送jar包:httpclient-4.5.5.jar; 赠送原API文档:httpclient-4.5.5-javadoc.jar; 赠送源代码:httpclient-4.5.5-sources.jar; 包含翻译后的API文档:httpclient-4.5.5-javadoc-API文档-中文(简体)版.zip ...

    httpclient-4.5.13-API文档-中英对照版.zip

    赠送jar包:httpclient-4.5.13.jar; 赠送原API文档:httpclient-4.5.13-javadoc.jar; 赠送源代码:httpclient-4.5.13-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.13.pom; 包含翻译后的API文档:...

    HTTPClient

    ### HTTPClient知识点详解 #### 1. HttpClient4 – 获取状态码 **1.1 概览** 本节将详细介绍如何使用HttpClient 4.x版本来获取HTTP响应的状态码,并对其进行验证。这对于开发人员来说是一个非常实用的功能,可以...

    httpClient组合包.zip

    此外,HttpClient还支持异步操作,可以在多线程环境中高效地处理并发请求。 2. **httpcore-4.4.12.jar**:这是HttpClient的核心库,包含了HTTP协议的基本组件,如连接管理、请求和响应模型、编码器和解码器等。...

    Java HttpClient 全部的jar包

    在Java项目中,使用HttpClient可以实现与Web服务器的高效通信。下面将详细介绍这12个jar包的作用及其在HttpClient中的功能: 1. `commons-beanutils-1.8.0.jar`: Apache Commons BeanUtils库提供了对Java Beans属性...

    Arduino HttpClient 库文件

    1. **实例化 HttpClient 对象**:首先,你需要创建一个 `HttpClient` 类的实例,例如 `HttpClient client;` 2. **设置服务器信息**:调用 `client.begin()` 函数,传入你要访问的服务器地址和端口号,如 `client....

Global site tag (gtag.js) - Google Analytics