CloseableHttpResponse response = httpclient.execute(httpPost);
int responseCode = response.getStatusLine().getStatusCode();
if(responseCode==200){
HttpEntity responseEntity = response.getEntity();
if(responseEntity!=null){
return EntityUtils.toByteArray(responseEntity);
}
}else if(responseCode==404){
throw new RpcException(RpcException.UNKNOWN_EXCEPTION,"not found service for url ["+url+"]");
}else if(responseCode==500){
throw new RpcException(RpcException.NETWORK_EXCEPTION,"occur an exception at server end.");
}
CloseableHttpResponse
需要在finally中关闭,不然responseCode
在不等于200
的情况下,连接就没关闭,导致连接泄露。