本文整理匯總了Java中org.apache.http.HttpStatus.SC_MOVED_PERMANENTLY屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.SC_MOVED_PERMANENTLY屬性的具體用法?Java HttpStatus.SC_MOVED_PERMANENTLY怎麽用?Java HttpStatus.SC_MOVED_PERMANENTLY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.SC_MOVED_PERMANENTLY屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: callWebProxy
public void callWebProxy(String url) {
String resultCode = "";
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
resultCode = ResponseCode.CALLRESPONSEERROR;
if (entity != null) {
String responseString = EntityUtils.toString(entity);
if (responseString.contains("Spark Jobs") && responseString.contains("Stages")
&& responseString.contains("Storage") && responseString.contains("Environment")
&& responseString.contains("Executors")) {
resultCode = ResponseCode.CALLSUCCESS;
}
}
} else if (statusCode == HttpStatus.SC_MOVED_TEMPORARILY
|| statusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
resultCode = ResponseCode.CALLFORBIDDEN;
} else {
resultCode = ResponseCode.OTHER_RESPONSE + String.valueOf(statusCode);
}
} catch (Exception e) {
LOG.warn("WebProxyCall exception " + e.getMessage());
resultCode = ResponseCode.CALLEXCEPTION;
} finally {
httpclient.close();
}
LOG.info("WebProxyCall result " + resultCode);
if (!resultCode.equals(ResponseCode.CALLSUCCESS)) {
System.exit(1);
}
}