获取多次重定向或转发后的页面状态码java

java多次重定向或转发后获取页面的状态码


String url=""; // 写想要获得状态码的网址
RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(5000)
	.setRedirectsEnabled(false).build();  // 不允许重定向
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(config).build();
int responseCode = 0;

HttpResponse response2;
response2 = httpClient.execute(new HttpGet(url));
responseCode = response2.getStatusLine().getStatusCode();

if(responseCode==200){
	System.out.println("成功");
}else{
	System.out.println("失败");
}

你可能感兴趣的:(技术积累,java)