- 浏览: 341419 次
- 性别:
- 来自: 重庆
文章分类
最新评论
-
hjl0722:
...
Java中的异或 -
lucd:
f(New.<Person, List<Pet&g ...
第15章泛型 -
liujunhao225:
[Error: could not access: List; ...
mvel的使用 -
superscorpio:
public void testImportInContex ...
mvel的使用 -
yuyangtina:
哦,知道了,是继承的方法。谢谢你的分享。
HttpClient3.x发送Soap请求的方法
一、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.
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.
发表评论
-
java发邮件
2013-05-07 16:55 882发邮件需要用到mail.jar包 import ja ... -
PropertyChangeSupport的使用
2012-12-20 14:06 2752import java.beans.PropertyCh ... -
JVM运行时数据区的划分
2012-11-28 09:20 863虚拟机运行时数据区 ... -
威风威风
2012-11-20 11:26 11031. //a 不 ... -
Http基本认证
2012-10-29 15:20 1007在HTTP中,基本认证是一种用来允许Web浏 ... -
如何获取美国时间
2012-10-26 10:41 2629TimeZone tz=TimeZone.getT ... -
base64加密算法简介
2012-10-23 11:32 1093什么是base64呢? 它是一种加密 ... -
比较器comparator
2012-10-11 10:46 814排序的规律跟方法的参数顺序有关。 该接口有个方法:in ... -
文件输入输出时的编码问题
2012-10-09 16:38 1070Java读取文件的 ... -
java源文件编码问题
2012-10-09 16:00 4664Java编译器在对 ... -
在java中利用ant对目录进行压缩
2012-08-31 17:05 914import java.io.File; impo ... -
File类中几个经常用到的方法
2012-07-30 16:02 2545一、File类的一些常用方法: 1.create ... -
文件读写例子
2012-07-07 10:19 989import java.io.BufferedReade ... -
字符串详解
2012-06-26 15:51 919一、字符串的六道经典题 看明白了,基本上就掌握了字符串的原理 ... -
私有成员的访问
2012-06-21 09:50 851不通过getXXX()方法获取类的私有域: public c ... -
jar文件
2012-05-31 23:41 1033JAR(Java Archive,Java 归档文件) ... -
mvel的使用
2012-05-23 16:03 10613MVEL is a powerful expressi ... -
NotePad++的格式编码
2012-04-25 10:01 11989notepad默认存储文件的格式是ansi格式,如果想修改,可 ... -
字符编码概述
2012-04-24 23:59 800ASCII码 我们知道,在计 ... -
http协议的消息头
2012-04-18 17:25 2667一、HTTP消息头主要分为 ...
相关推荐
《深入解析httpclient.jar及其与code.jar的关联》 在Java开发中,HTTP通信是不可或缺的一部分,而Apache HttpClient库正是Java实现HTTP客户端操作的重要工具。本文将深入探讨httpclient.jar包,以及它与code.jar包...
### Httpclient官网教程中文版知识点总结 #### 一、引言 HTTP协议作为互联网的核心通信标准之一,在现代网络服务及物联网设备中扮演着至关重要的角色。随着技术的发展,越来越多的应用和服务依赖于HTTP协议来实现...
HttpClient 4.2.1版本引入了一些重要的改进和修复,以提高性能和稳定性。以下是一些关键特性: 1. **连接管理**:HttpClient 4.2.1引入了更完善的连接管理机制,允许开发者控制连接的创建、复用和关闭。`...
例如,在HttpClient 3.x中,代码可能会使用`***mons.httpclient.HttpClient`类和`***mons.httpclient.methods.GetMethod`等,而在4.x版本中,这些都被新的API所替代。程序员需要熟悉`org.apache....
赠送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...
本文将深入探讨HttpClient 4.2.1的核心特性和使用方法,帮助开发者更好地理解和应用这个强大的工具。 一、HttpClient简介 HttpClient是一个开放源码的Java库,由Apache软件基金会维护。它为Java程序员提供了一个...
HttpClient httpClient = new HttpClient(); // 设置 Http 连接超时为5秒 httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); /* 2 生成 GetMethod 对象并设置参数 */ GetMethod ...
赠送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方式调用URL,以及相关的知识点。 首先,HttpClient允许我们构建复杂的HTTP请求,包括GET、POST以及其他HTTP方法。使用HttpClient调用URL的基本步骤包括创建HttpClient实例、...
使用HttpClient发送请求、接收响应很简单,一般需要如下几步即可。 1. 创建HttpClient对象。 2. 创建请求方法的实例,并指定请求URL。如果需要发送GET请求,创建HttpGet对象;如果需要发送POST请求,创建...
HttpClientHelper 对这个类进行了封装,使得开发者无需直接与HttpClient接口打交道,而是通过更简洁、易用的方法调用来实现网络通信。这提高了代码的可读性和可维护性。 单例模式是软件设计模式的一种,确保一个类...
HttpClient 4.13版本是这个库的一个较新版本,包含了一系列的改进和修复。 在Java开发中,HttpClient是一个常用的工具,尤其在处理Web服务或者API调用时。它支持同步和异步操作,可以处理复杂的HTTP协议细节,使...
这个实例主要涉及如何配置HttpClient来忽略SSL(Secure Socket Layer)验证,这对于在开发和测试环境中处理自签名证书或未认证的服务器非常有用。以下将详细介绍HttpClient的使用以及如何进行SSL验证的忽略。 首先...
《HttpClient 4.5详解与应用实践》 HttpClient是一个开源的Java库,由Apache软件基金会维护,主要用于在HTTP协议上实现客户端的通信。版本4.5是HttpClient的一个稳定版本,提供了许多增强的功能和优化,使其成为...
本压缩包文件"httpClient"很可能包含了HttpClient库所需的必备JAR文件,这些文件通常包括HttpClient的核心库、依赖的第三方库以及可能的扩展模块。为了正确使用HttpClient,你需要确保将这些JAR文件添加到你的项目类...
《深入理解HTTPClient 4.5及其依赖》 在Java编程世界中,HTTPClient是一个非常重要的库,它允许开发者执行HTTP请求并处理响应。本文将深入探讨`httpclient-4.5.jar`这个包,以及它所依赖的相关jar包,帮助你更好地...
在本文中,我们将深入探讨如何使用HttpClient调用WebService。 首先,调用WebService通常涉及SOAP(Simple Object Access Protocol)或RESTful API。HttpClient可以处理这两种类型的Web服务。在本示例中,我们假设...
赠送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文档:...
赠送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知识点详解 #### 1. HttpClient4 – 获取状态码 **1.1 概览** 本节将详细介绍如何使用HttpClient 4.x版本来获取HTTP响应的状态码,并对其进行验证。这对于开发人员来说是一个非常实用的功能,可以...