@Contract(threading=IMMUTABLE) public class DefaultRedirectStrategy extends Object implements RedirectStrategy
RedirectStrategy 。
此策略可以实现对HTTP规范强加的实体封装方法(如POST和PUT)的自动重定向的限制。
302 Moved Temporarily , 301 Moved Permanently和307 Temporary Redirect状态码将导致头的自动重定向并仅GET方法。
POST和PUT方法将不会自动重定向,因为需要用户确认。
通过使用LaxRedirectStrategy而不是DefaultRedirectStrategy可以放宽对POST方法自动重定向的限制。
LaxRedirectStrategy
| Modifier and Type | Field and Description |
|---|---|
static DefaultRedirectStrategy |
INSTANCE |
static String |
REDIRECT_LOCATIONS
已过时。
(4.3)使用
HttpClientContext.REDIRECT_LOCATIONS 。
|
| Constructor and Description |
|---|
DefaultRedirectStrategy() |
| Modifier and Type | Method and Description |
|---|---|
protected URI |
createLocationURI(String location) |
URI |
getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) |
HttpUriRequest |
getRedirect(HttpRequest request, HttpResponse response, HttpContext context)
确定给定来自目标服务器和当前请求执行上下文的响应的重定向位置,并生成要发送到该位置的新请求。
|
protected boolean |
isRedirectable(String method) |
boolean |
isRedirected(HttpRequest request, HttpResponse response, HttpContext context)
确定一个请求是否应该被重定向到一个新的位置,给定来自目标服务器的响应。
|
@Deprecated public static final String REDIRECT_LOCATIONS
HttpClientContext.REDIRECT_LOCATIONS 。
public static final DefaultRedirectStrategy INSTANCE
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException
RedirectStrategy复制
isRedirected在接口
RedirectStrategy
request - 执行的请求
response - 从目标服务器收到的响应
context - 请求执行的上下文
true如果请求被重定向,否则
false
ProtocolException
public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException
protected URI createLocationURI(String location) throws ProtocolException
ProtocolException
protected boolean isRedirectable(String method)
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException
RedirectStrategy复制
getRedirect在接口
RedirectStrategy
request - 执行的请求
response - 从目标服务器收到的响应
context - 请求执行的上下文
ProtocolException
Copyright © 1999–2017 The Apache Software Foundation. All rights reserved.