本文整理汇总了Java中org.apache.http.HttpStatus.SC_TEMPORARY_REDIRECT属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.SC_TEMPORARY_REDIRECT属性的具体用法?Java HttpStatus.SC_TEMPORARY_REDIRECT怎么用?Java HttpStatus.SC_TEMPORARY_REDIRECT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.SC_TEMPORARY_REDIRECT属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isRedirected
public boolean isRedirected(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
int statusCode = response.getStatusLine().getStatusCode();
String method = request.getRequestLine().getMethod();
Header locationHeader = response.getFirstHeader("location");
switch (statusCode) {
case HttpStatus.SC_MOVED_TEMPORARILY:
return isRedirectable(method) && locationHeader != null;
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_TEMPORARY_REDIRECT:
return isRedirectable(method);
case HttpStatus.SC_SEE_OTHER:
return true;
default:
return false;
} //end of switch
}
示例2: isRedirectRequested
public boolean isRedirectRequested(
final HttpResponse response,
final HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_TEMPORARY_REDIRECT:
HttpRequest request = (HttpRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);
String method = request.getRequestLine().getMethod();
return method.equalsIgnoreCase(HttpGet.METHOD_NAME)
|| method.equalsIgnoreCase(HttpHead.METHOD_NAME);
case HttpStatus.SC_SEE_OTHER:
return true;
default:
return false;
} //end of switch
}
示例3: isRedirectRequested
@Override
public boolean isRedirectRequested(
final HttpResponse response,
final HttpContext context) {
if (!enableRedirects) {
return false;
}
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_SEE_OTHER:
case HttpStatus.SC_TEMPORARY_REDIRECT:
return true;
default:
return false;
} //end of switch
}
示例4: record
private Response record(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
NetworkCallRecord networkCallRecord = new NetworkCallRecord();
networkCallRecord.Headers = new HashMap<>();
if (request.header("Content-Type") != null) {
networkCallRecord.Headers.put("Content-Type", request.header("Content-Type"));
}
if (request.header("x-ms-version") != null) {
networkCallRecord.Headers.put("x-ms-version", request.header("x-ms-version"));
}
if (request.header("User-Agent") != null) {
networkCallRecord.Headers.put("User-Agent", request.header("User-Agent"));
}
networkCallRecord.Method = request.method();
networkCallRecord.Uri = applyReplacementRule(request.url().toString().replaceAll("\\?$", ""));
Response response = chain.proceed(request);
networkCallRecord.Response = new HashMap<>();
networkCallRecord.Response.put("StatusCode", Integer.toString(response.code()));
extractResponseData(networkCallRecord.Response, response);
// remove pre-added header if this is a waiting or redirection
if (networkCallRecord.Response.get("Body").contains("<Status>InProgress</Status>")
|| Integer.parseInt(networkCallRecord.Response.get("StatusCode")) == HttpStatus.SC_TEMPORARY_REDIRECT) {
// Do nothing
} else {
synchronized (recordedData.getNetworkCallRecords()) {
recordedData.getNetworkCallRecords().add(networkCallRecord);
}
}
return response;
}
示例5: isTemporaryRedirect
private static boolean isTemporaryRedirect(org.apache.http.HttpResponse response) {
int status = response.getStatusLine().getStatusCode();
return status == HttpStatus.SC_TEMPORARY_REDIRECT && response.getHeaders("Location") != null
&& response.getHeaders("Location").length > 0;
}