请求拦截器HttpRequestInterceptor
来源:互联网 发布:淘宝模特tim 编辑:程序博客网 时间:2024/06/05 02:07
public interface
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头的处理,但是它们的使用还不清楚。
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头的处理,但是它们的使用还不清楚。
- 请求拦截器HttpRequestInterceptor
- ClassNotFoundException HttpRequestInterceptor
- struts2的拦截器拦截ajax请求
- 使用拦截器来拦截请求handlerInterceptor
- 自定义拦截器GET请求POST请求
- okhttp拦截器网络请求
- Android_拦截器请求头
- 自定义拦截器 post请求
- 拦截器的请求头
- SpringMVC学习笔记--拦截器拦截Request请求
- resteasy拦截器,拦截rest请求,修改response header内容
- Spring中使用Interceptor拦截器拦截请求
- struts2设置拦截器不拦截某请求
- 实现Spring拦截器拦截ajax请求并重定向
- spring mvc 拦截器拦截 js,css等请求,
- struts2 拦截器 请求参数 更改
- struts2拦截器获取请求相关内容
- Filter拦截器获取请求相关内容
- 在linux下将html格式转换成xml格式
- Excel VBA - 遍历某个文件夹中文件、文件夹及批量建立txt
- 对mysql explain讲的比较清楚的
- Jquery $.post()方法中 url过长及中文问题
- ExpandableListView学习
- 请求拦截器HttpRequestInterceptor
- 搜索引擎营销:你选什么作为关键词
- c++ string使用详解
- MySql-Proxy Introduction
- ubuntu下安装wine1.2.3
- 自解压
- 关于大脑
- Ubuntu和Android的问题
- oracle lag和lead函数