請求攔截器HttpRequestInterceptor

來源:互聯網
上載者:User

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頭的處理,但是它們的使用還不清楚。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.