怎么看cpu风扇转速-微信网络设置
![generic host](/uploads/image/0968.jpg)
2023年4月3日发(作者:电信无线账号)
ResponseExceptionhost
端口failedtorespond错误原因和解决方法
rayContent;
cUrl;
import
ckOffUnsuccessfulRespo
nseHandler;
ntent;
aders;
quest;
questFactory;
sponse;
atusCodes;
ansport;
import
HttpTransport;
f;
ption;
tream;
elector;
;
;
ask;
it;
troy;
;
4j;
Element;
ElementIterator;
st;
ConnectionManager;
import
tionKeepAliveStrategy;
import
nagerParams;
rRouteBean;
ocketFactory;
;
Registry;
ketFactory;
tHttpClient;
import
tHttpRequestRetryHandl
er;
import
electorRoutePlanner;
import
SafeClientConnM
anager;
import
eaderElementIterator;
ttpParams;
nnectionParams;
rams;
;
ntext;
/**
*@authorLiSheng
*/
@Slf4j
publicclassHttpClientUtils{
privatestaticHttpRequestFactoryrequestFactory;
privatestaticHttpTransporthttpTransport;
privatestaticfinalStringCONTENT_TYPE_JSON=
"application/json";
privatestaticfinalintCACHE_SIZE=4096;
static{
HttpParamsparams=newBasicHttpParams();
leCheckingEnabled(params,
false);
ketBufferSize(params,
245760);//8k(8192)*30
TotalConnections(params,
400);
ConnectionsPerRoute(para
ms,newConnPerRouteBean(200));
SchemeRegistryregistry=newSchemeRegistry();
er(newScheme("http",
ketFactory(),80));
er(newScheme("https",
ketFactory(),443));
ClientConnectionManagerconnectionManager=new
ThreadSafeClientConnManager(params,registry);
DefaultHttpClientdefaultHttpClient=new
DefaultHttpClient(connectionManager,params);
pRequestRetryHandler(new
DefaultHttpRequestRetryHandler(0,false));
defaultHttpClient
.setRoutePlanner(new
ProxySelectorRoutePlanner(registry,
ault()));
ConnectionKeepAliveStrategy
connectionKeepAliveStrategy=new
ConnectionKeepAliveStrategy(){
@Override
publiclong
getKeepAliveDuration(sponse
httpResponse,
HttpContexthttpContext){
return20*1000;//20seconds,becausetomcat
defaultkeep-alivetimeoutis20s
}
};
pAliveStrategy(connectionKeepAli
veStrategy);
httpTransport=new
ApacheHttpTransport(defaultHttpClient);
requestFactory=
RequestFactory();
}
@Data
publicstaticclassPostParam{
privateIntegerconnectTimeoutMills;//可选,默认
20s
privateIntegerreadTimeoutMills;//可选,默认20s
privateMapheaders;//可选
privateStringurl;//必填
privateStringpostJson;//必填
privateBooleanreadResponseData;//必填:是否需要
读取数据。如果不需要返回结果,设置false
privateBackOffbackOff;//可选,重试机制策略
privateStringauthorization;//可选
publicPostParam(Stringurl,StringpostJson,boolean
readResponseData){
=url;
on=postJson;
sponseData=readResponseData;
}
}
publicstaticStringpostWithJson(PostParampostParam)
{
GenericUrlgenericUrl=new
GenericUrl(());
HttpContenthttpContent=
ring(null,
tJson());
HttpResponsehttpResponse=null;
try{
HttpRequesthttpRequest=
ostRequest(genericUrl,
httpContent);
if(nectTimeoutMills()!=null){
nectTimeout(nectTi
meoutMills());
}
if(dTimeoutMills()!=null){
dTimeout(dTimeout
Mills());
}
if(kOff()!=null){
uccessfulResponseHandler(
new
HttpBackOffUnsuccessfulResponseHandler(
tBackOff()));
}
HttpHeadershttpHeaders=newHttpHeaders();
tentType(CONTENT_TYPE_JSON);
Mapheaders=ders();
if(headers!=null&&()>0){
h(httpHeaders::set);
}
if(horization()!=null
&&!("")){
horization(horization(
));
}
ders(httpHeaders);
httpResponse=e();
if(tusCode()!=
_CODE_OK){
("httpstatusnot200.
param:{},status:{},msg:{}",postParam,
tusCode(),
tusMessage());
returnnull;
}
BooleanreadResponseData=
dResponseData();
if(readResponseData!=null&&
readResponseData){
InputStreaminputStream=
tent();
if(inputStream!=null){
StringBufferout=newStringBuffer();
byte[]b=newbyte[CACHE_SIZE];
for(intn;(n=(b))!=-1;){
(newString(b,0,n));
}
ng();
}
}
}catch(Exceptione){
("postexception,param:{}",postParam,e);
}finally{
try{
if(httpResponse!=null){
nect();
}
}catch(Exceptione){
("httpResponsedisconnectexception",
e);
}
}
returnnull;
}
@PreDestroy
publicstaticvoiddestory(){
try{
("httpTransportshutdownnow....");
wn();
}catch(IOExceptione){
("shutdownhttpTransportexception",e);
}
}
}
更多推荐
generic host
发布评论