HttpRequestInterceptor
org.apache.http.HttpRequestInterceptor
Known Indirect Subclasses
BasicHttpProcessor, HttpProcessor, RequestAddCookies, RequestConnControl, RequestContent,
RequestDate, RequestDefaultHeaders, RequestExpectContinue, RequestProxyAuthentication,
RequestTargetAuthentication, RequestTargetHost, RequestUserAgent
BasicHttpProcessor Keeps lists of interceptors for processing requests and responses.
HttpProcessor Performs interceptor processing of requests and responses.
RequestAddCookies Request interceptor that matches cookies available in the current CookieStore to the request being executed and generates corresponding cookierequest headers.
RequestConnControl A request interceptor that suggests connection keep-alive to the server.
RequestContent A request interceptor that decides about the transport encoding.
RequestDate A request interceptor that adds a Date header.
RequestDefaultHeaders Request interceptor that adds default request headers.
RequestExpectContinue A request interceptor that enables the expect-continue handshake.
RequestProxyAuthentication
RequestTargetAuthentication
RequestTargetHost A request interceptor that sets the Host header for HTTP/1.1 requests.
RequestUserAgent A request interceptor that adds a User-Agent header.
Class Overview
Processes a request. Provides the ability to process a request before it is sent to the server
or after it has received on the server side.
HttpRequestInterceptor就是Http请求拦截器。
可用在客服端,在Http消息发出前,对HttpRequest request做些处理。比如加头啊
也可用在服务器端,在Http到达后,正式处理前,对HttpRequest request做些处理。
HttpRequestInterceptor声明了一个方法(只有一个)以便处理HttpRequest request。
Public Methods
public abstract void process (HttpRequest request, HttpContext context)
Since: API Level 1
Processes a request. On the client side, this step is performed before the request is sent to the server. On the server side, this step is performed on incoming messages before the message body is evaluated.
Parameters
request the request to preprocess
context the context for the request
Throws
IOException in case of an IO problem
HttpException in case of a protocol or other problem
HttpRequestInterceptor用在客服端时,在http消息发送到服务器前,该方法被调用。
HttpRequestInterceptor用在服务器端时,在http消息到达服务器后,但在被系统处理前,该方法被调用。
示例1:
DefaultHttpClient client=new DefaultHttpClient();
.................................
if(sendHeaders.size()>0)
{
HttpRequestInterceptor itcp=new HttpRequestInterceptor()
{
public void process(HttpRequest request, HttpContext context)
throws HttpException,IOException
{
for(String key:sendHeaders.keySet())
{
if(!request.containsHeader(key))
{
request.addHeader(key,sendHeaders.get(key));
}
}
}
};
client.addRequestInterceptor(itcp);
}
注意:RequestAddCookies, RequestConnControl, RequestContent,
RequestDate, RequestDefaultHeaders, RequestExpectContinue, RequestProxyAuthentication,
RequestTargetAuthentication, RequestTargetHost, RequestUserAgent
它们好像是对应Http头的处理,但是它们的使用还不清楚。
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net