关于JAVA HttpClient链接超时问题

在项目中运用到了httpclient进行发送和接受请求,不知道为什么再走断点进行一步一步的查看代码的时候 走到这一步会出现链接超时,而如果不走断点却没有问题。
时间设置我设置成了30000000毫秒,走断点一直没有反应,等待遥遥无期,设置成30秒缺超时,请求大神帮忙解答疑问,是我eclipse的问题还是项目代码的问题?

1个回答

是异步调用的么?是不是后续代码在访问网页前就返回了。要具体看下你的代码

qq_32252023
qq_32252023 在用executeMethod这个方法的时候出现的问题。
接近 4 年之前 回复
qq_32252023
qq_32252023 int statusCode = http.executeMethod(postMethod);
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Httpclient4.3 设置请求超时的问题呢

问题描述: 多线程使用httpclient调用接口时,一直保持响应,连接不断开。 增加了线程了,和超时的设置,但是仍然不能保证响应过长,断开连接。 把工具的设置贴上来 ``` private static final CloseableHttpClient httpClient; public static final String CHARSET_GBK = "GBK"; public static final String CHARSET_UTF8 = "UTF-8"; // 将最大连接数增加到 public static final int MAX_TOTAL = 600; // 将每个路由基础的连接增加到 public static final int MAX_ROUTE_TOTAL = 300; //设置超时时间 public static final int REQUEST_TIMEOUT = 2 * 1000; public static final int REQUEST_SOCKET_TIME = 2 * 1000; static { // 设置连接超时 的时间 PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager(); httpClientConnectionManager.setMaxTotal(MAX_TOTAL); httpClientConnectionManager.setDefaultMaxPerRoute(MAX_ROUTE_TOTAL); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(REQUEST_TIMEOUT) .setSocketTimeout(REQUEST_SOCKET_TIME).build(); // 设置重定向策略 LaxRedirectStrategy redirectStrategy = new LaxRedirectStrategy(); httpClient = HttpClients.custom() .setConnectionManager(httpClientConnectionManager) .setDefaultRequestConfig(requestConfig) .setRedirectStrategy(redirectStrategy).build(); } ``` 使用这个工具自己用了两个测试,一个是测试请求时间,一个测试的响应时间,都能正常的抛出错误。 测试1、请求了google的地址,报错:java.net.SocketTimeoutException: Read timed out 测试2、请求一个测试接口,接口中对请求休眠2000ms ``` try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "hello world"; ``` 运行结果:Caused by: java.net.SocketTimeoutException: connect timed out 但是把这个部署到服务器上后,使用对方的接口,如果对方处理的时间过长,连接就一直不会断开。导致处理速度一直被拖累。 ![图片说明](https://img-ask.csdn.net/upload/201509/18/1442566513_618072.jpg) 请问这种情况能否解决?

访问外网接口 在服务器上curl没有问题 但是使用httpclient就超时

访问外网接口 在服务器上curl没有问题 但是使用httpclient就超时 能是什么原因啊 求大神帮忙解决

httpclient连接超时了!!!各位进来看一下啊

我知道如何设置httpclient如何设置连接超时,和读取数据超时,但是我想知道如何判断连接超时 [code="java"]client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); client.getHttpConnectionManager().getParams().setSoTimeout(5000);[/code] 我想写的语句是这样的 :如果连接超时 则执行函数mothod1,否则执行函数Mothod2,请问这段代码该怎么写呢? [code="java"]if(连接超时) [b]//谁能帮我完成这个语句?[/b] mothod1(); else mothod2();[/code]

httpclient-4.5.2读取超时,重发没起到作用,为什么?

1、写了一个httpclient的工具类,也写了重试的逻辑, 但是在多个线程在使用同一个httpclient实例的时候, 发现线程read time out的超时并没有被重发很郁闷(线程直接进入的SocketTimeoutException异常, 导致本次线程的请求没有拿到再次重发后的结果,导致数据丢失) public CloseableHttpClient getHttpClient() { return HttpClients.custom(). setConnectionManager(connMrg). setKeepAliveStrategy(myStrategy). setDefaultRequestConfig(requestConfig). setConnectionManagerShared(true). setMaxConnTotal(maxTotal). setRetryHandler( new HttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception , int executionCount , HttpContext context) { // 重试3次,从3开始 if (executionCount > 3) { return false; } /* if (exception instanceof NoHttpResponseException) { System.out.println( "[NoHttpResponseException has retry request:" + context.toString() + "][executionCount:" + executionCount + "]"); return true; } else if (exception instanceof SocketException || exception instanceof ConnectTimeoutException || exception instanceof SocketTimeoutException ) { System.out.println("[SocketException has retry request:" + context.toString() + "][executionCount:" + executionCount + "]"); return true; } */ if (exception instanceof UnknownHostException) { return false; } // SSL handshake exception if (exception instanceof SSLException) { return false; } //除上述两种异常其他异常均重试3次,其实主要问题在于 //服务端对连接数限制,会导致你再怎么重试,都会异常,连接数满了,重试还有毛用 //所以设置连接池的时候需要设置的比他们的最大值小,用完要及时释放到连接池 String time3 = new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()); System.out.println("time:"+time3+"="+Thread.currentThread().getName() +"\n"+"[Exception:"+exception.toString()+" has retry request:" + context.toString() + "][executionCount:" + executionCount + "]"); return true; } } ). build(); } 问题3: String time3 = new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()); System.out.println("time:"+time3+"="+Thread.currentThread().getName() +"\n"+"[Exception:"+exception.toString()+" has retry request:" + context.toString() + "][executionCount:" + executionCount + "]"); return true; 这段代码发生read time out的时候执行了,但是executionCount一直都是1,我理解应该是重发了一次,但是子线程里的日志打印了异常,并没有获取到重试后的结果 问题4,子线程取数据逻辑,只写了主要逻辑 httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8"); // httpPost.setHeader("SOAPAction", ""); StringEntity data = new StringEntity(inputPara, Charset.forName("UTF-8")); httpPost.setEntity(data); try { response = httpClient.execute(httpPost); httpEntity = response.getEntity(); if (httpEntity != null) { // 获取响应内容 returnVal = EntityUtils.toString(httpEntity, "UTF-8"); // 消费掉节约内存,并关闭inputstream流 EntityUtils.consume(httpEntity); } } catch (Exception e) { e.printStackTrace(); } finally { try { // 关闭流并释放资源 response.close(); } catch (Exception e) { e.printStackTrace(); } } 我认为在这段的httpEntity = response.getEntity();执行的时候 readtime out,然后代码直接进入了catch逻辑,所以重发后的结果并没有取到。 问题5: 1、我就是想解决,读取超时就重发,一直到3次结束。 2、是不是我设置的读取超时时间为60s导致根本没办法重发,服务端可能已经把短连接关闭了 因为http默认短连接时间好像就是60s。我猜测,如果我设置读取时间为10s,可能就可以重试3次了。 3、 try{ httpEntity = response.getEntity(); } catch() { } 这段逻辑跟 创建httpclient的方法里面的重试方法,当发生异常时,到底是这段阻塞httpEntity = response.getEntity(); 等待3次重发?还是是异步的,里面重发,外面直接进入异常逻辑,根本不等重发后的结果

httpclient怎么设置连接池连接等待时间

连接满时,会处于连接池等待状态,怎么设置连接池等待时间,避免造成长时间等待 求大神解答,急!在线等!!!! /*读取超时*/ private final static int SOCKET_TIMEOUT = 50000; /*连接超时*/ private final static int CONNECTION_TIMEOUT = 50000; /*每个HOST的最大连接数量*/ private final static int MAX_CONN_PRE_HOST = 2; /*连接池的最大连接数*/ private final static int MAX_CONN = 60; /*连接池*/ private final static HttpConnectionManager httpConnectionManager; static{ httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = httpConnectionManager.getParams(); params.setConnectionTimeout(CONNECTION_TIMEOUT); params.setSoTimeout(SOCKET_TIMEOUT); params.setDefaultMaxConnectionsPerHost(MAX_CONN_PRE_HOST); params.setMaxTotalConnections(MAX_CONN); }

java下载网络文件时连接超时

错误信息: java.net.ConnectException: Connection timed out java.net.PlainSocketImpl.socketConnect(Native Method) java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) java.net.Socket.connect(Socket.java:529) java.net.Socket.connect(Socket.java:478) sun.net.NetworkClient.doConnect(NetworkClient.java:163) sun.net.www.http.HttpClient.openServer(HttpClient.java:394) sun.net.www.http.HttpClient.openServer(HttpClient.java:529) sun.net.www.http.HttpClient.<init>(HttpClient.java:233) sun.net.www.http.HttpClient.New(HttpClient.java:306) sun.net.www.http.HttpClient.New(HttpClient.java:323) sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970) sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911) sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836) sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172) java.net.URL.openStream(URL.java:1010) com.srt.ezg.eMeg.voiceMail.action.VoiceAction.voiceDownload(VoiceAction.java:189) sun.reflect.GeneratedMethodAccessor3167.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280) org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216) org.apache.struts.actions.DispatchAction$$FastClassByCGLIB$$d3d27916.invoke(<generated>) net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635) com.srt.ezg.eMeg.voiceMail.action.VoiceAction$$EnhancerByCGLIB$$e77a6b68.execute(<generated>) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) com.srt.vas.filter.OaFilter.doFilter(OaFilter.java:68) com.srt.vas.filter.SetFilterEcod.doFilter(SetFilterEcod.java:25) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:359) org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) com.srt.sdp.security.bean.CustomFilterSecurityInterceptor.invoke(CustomFilterSecurityInterceptor.java:117) com.srt.sdp.security.bean.CustomFilterSecurityInterceptor.doFilter(CustomFilterSecurityInterceptor.java:86) com.srt.sdp.security.bean.CustomFilterSecurityInterceptor$$FastClassByCGLIB$$2c376577.invoke(<generated>) net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) com.srt.interceptor.MethodTimeAdvice.invoke(MethodTimeAdvice.java:34) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635) com.srt.sdp.security.bean.CustomFilterSecurityInterceptor$$EnhancerByCGLIB$$635d6668.doFilter(<generated>) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:173) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:271) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:271) org.springframework.security.ui.AbstractProcessingFilter$$FastClassByCGLIB$$32042740.invoke(<generated>) net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635) com.srt.sdp.security.bean.CustomAuthenticationProcessingFilter$$EnhancerByCGLIB$$3e18fe7e.doFilterHttp(<generated>) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235) org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371) org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:174) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) ----------------------------------------------- VoiceAction.java中的下载action: try { request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { } String path = request.getParameter("url");// 语音文件下载地址 path = new String(path .getBytes("ISO-8859-1"), "UTF-8"); // path="http://127.0.0.1/Ezg_v4.0/a059516000101001.wav"; int startIndex = path.lastIndexOf("/"); int endIndex = path.length(); String fileName = path.substring(startIndex + 1, endIndex); BufferedInputStream bis = null; BufferedOutputStream bos = null; OutputStream fos = null; InputStream fis = null; URL url = new URL(path); try { fis = url.openStream();//这行报错 bis = new BufferedInputStream(fis); fos = response.getOutputStream(); bos = new BufferedOutputStream(fos); response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("gb2312"), "ISO-8859-1")); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, bytesRead); } bos.flush(); fis.close(); bis.close(); fos.close(); bos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } return null; ---------------------------------------------------- 首先,代码应该是没有问题的。 报错的位置是在fis = url.openStream()这里。 VoiceAction.java:189 请问,应该从哪里着手解决?

httpClient execute方法经常发生超时 sockettimeoutException

HttpResponse response = mHttpClient.execute(request); 执行时经常报SocketTimeoutException 在开发环境上测试都没有出现过这样的情况,且服务器端打印不出任何日志,感觉是请求没有发送到服务器端。

求解httpClient发送请求访问接口时,有时能连接,有时连接不上

RT:求解httpClient发送请求访问接口时,有时能连接,有时连接不上,连接上了以后,下一次查询很快,求大神帮忙查看,感谢。 问题: 1、使用的是 org.apache.http.impl.client.CloseableHttpClient; 2、访问接口时,有时能连接,有时连接不上 备注: 1、因为公司的策略情况,使用的是http1.0的中的短连接。使用抓包工具看,连接不上的时候一直是TCP重连,待超过设置的超时时间后查询不到数据。 2、网上查看了有说超时时间太长,设置短了更查不到数据 3、应用部署使用tomcat和docker都试过,效果一样。 4、接口是提供给多个系统使用,只有我调用存在此类问题。 5、使用postman调用速度比代码调用快。 抓包内容 : ![图片说明](https://img-ask.csdn.net/upload/201908/19/1566215766_686306.png) httpClient代码 ``` public static String postRequest(String url, String jsonString){ CloseableHttpResponse httpResponse = null; HttpPost httpPost = new HttpPost(url); RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(60000) .setConnectTimeout(60000) .build(); CloseableHttpClient httpClient = HttpClients.custom() .setDefaultRequestConfig(requestConfig) .build(); //使用http1.0的短连接 httpPost.setProtocolVersion(HttpVersion.HTTP_1_0); httpPost.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE); httpPost.setConfig(requestConfig); httpPost.addHeader("Content-Type", "application/json"); StringEntity requestEntity = new StringEntity(jsonString, "utf-8"); httpPost.setEntity(requestEntity); try { httpResponse = httpClient.execute(httpPost); if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { return null; } HttpEntity entity = httpResponse.getEntity(); if (entity != null) { String resultStr = EntityUtils.toString(entity, "utf-8"); return resultStr; } else { return null; } } catch (Exception e) { logger.error("httpPost method exception handle-- > " + e); return null; } finally { if (httpResponse != null){ try { httpResponse.close(); } catch (IOException e) { logger.error("httpPost method IOException handle -- > " + e); } } if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { logger.error("httpPost method exception handle-- > " + e); } } } } ```

使用Java,如何给Android设置 HttpResponse超时?

为了检查网络连接的情况,我创建了下边的方法: private void checkConnectionStatus() { HttpClient httpClient = new DefaultHttpClient(); try { String url = "http://xxx.xxx.xxx.xxx:8000/GaitLink/" + strSessionString + "/ConnectionStatus"; Log.d("phobos", "performing get " + url); HttpGet method = new HttpGet(new URI(url)); HttpResponse response = httpClient.execute(method); if (response != null) { String result = getResponse(response.getEntity()); ... 当我关闭服务器来测试执行的时候,需要等待很长的时间 HttpResponse response = httpClient.execute(method); 有人知道怎么设置超时来避免等待太长的时间吗? 谢谢!

JAVA如何模拟网络超时?

如题,想测试下在各种网络条件下程序的运行情况,比如我以HttpClient发起请求想测试下超时状态该如何做?

httpclient 连接被拒绝问题。

我使用httpclient模拟客户端访问某个大型网站,我每次访问的是其中不同的一个网页。频率为每15秒访问一次。但是在过了一段时间以后,就会跳出异常显示我的访问被拒绝了。 我手动修改ip地址以后又好了。有没有什么方便的方法可以让访问不再被拒绝啊? 频率再降低?还是搞个什么自动修改ip地址。

url在建立连接的时候,包连接超时,偶先现象。

java代码如下 String netUrl = map.get("url"); URL url = new URL(netUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5 * 1000); 上面的代码在生产环境执行这一行:HttpURLConnection conn = (HttpURLConnection) url.openConnection();的时候,会报错(偶先报错)。 报错如下: java.net.SocketTimeoutException: connect timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at sun.net.NetworkClient.doConnect(NetworkClient.java:175) at sun.net.www.http.HttpClient.openServer(HttpClient.java:432) at sun.net.www.http.HttpClient.openServer(HttpClient.java:527) at sun.net.www.http.HttpClient.<init>(HttpClient.java:211) at sun.net.www.http.HttpClient.New(HttpClient.java:308) at sun.net.www.http.HttpClient.New(HttpClient.java:326) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1168) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:932) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440) at com.aihui.community.controller.CurrentUploadFile.netUrl(CurrentUploadFile.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:167) at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) 有朋友知道为啥吗?谢谢了,急需解决,我对这方面不是太了解。

httpClient 3如何session会话保持?

问题场景: 通过httpClient请求同一门户的接口地址,因为登录后和未登录的时候返回的数据不一样。所以当用户在门户上登录的情况下,访问接口返回的数据也应该是要登录口的数据。现在返回的都是未登录的情况。‘请问大神们此问题如何解决。 代码如下: String url = "http://192.168.41.56/portal/480/home/wap/xqy/ljjk/dbjqbf/index.jsp"; String result = ""; HttpClient client = new HttpClient(); //client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); HttpConnectionManagerParams managerParams = client.getHttpConnectionManager().getParams(); // 设置连接超时时间(单位毫秒) managerParams.setConnectionTimeout(500); managerParams.setSoTimeout(5000); GetMethod getMethod=new GetMethod(); URI base = new URI(url,false); getMethod.setURI(new URI(base,"",false)); int resultCode = client.executeMethod(getMethod); if(resultCode == 200 ) { byte[] body=getMethod.getResponseBody(); if(body!=null && body.length>0){ result=new String(body,"UTF-8"); System.out.println(result); }else{ System.out.println(" 无返回值 url ="+url); } }else{ System.out.println(" HTTP 返回异常 url ="+url +", resultCode= "+ resultCode); } getMethod.releaseConnection();

java读取网页数据超时

[code="java"]public static void main(String[] args) throws IOException { getWebData("http://bbs.csdn.net/topics/380263902"); } private static String getWebData(String strurl) { try { URL url = new URL(strurl); // 打开连接,此处只是创建一个实例,并没有真正的连接 HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setConnectTimeout(300000); httpCon.setReadTimeout(300000); httpCon.connect();//建立连接 InputStream inputStream = httpCon.getInputStream(); InputStreamReader inputReader = new InputStreamReader(inputStream,"utf-8"); BufferedReader bufferReader = new BufferedReader(inputReader); StringBuffer sb = new StringBuffer(); String inputLine = null; while ((inputLine = bufferReader.readLine()) != null) { sb.append(inputLine+"\n"); } bufferReader.close(); inputReader.close(); inputStream.close(); httpCon.disconnect(); System.out.println(sb.toString().trim()); return sb.toString(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("======================================================="); return null; }[/code] 代码如上,但是执行上面代码报如下错误 java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.<init>(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) at test.getWebData(test.java:30) at test.main(test.java:18) 我通过IE浏览器是可以打开http://bbs.csdn.net/topics/380263902该页面的,但是通过代码就不能获取页面数据,不知道是什么原因

CAS 线上登录成功后不跳转 提示连接超时

2018-11-06 16:31:47 ERROR [http-bio-6060-exec-2] org.jasig.cas.client.util.CommonUtils - 连接超时 java.net.ConnectException: 连接超时 at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at java.net.Socket.connect(Socket.java:528) at sun.net.NetworkClient.doConnect(NetworkClient.java:180) at sun.net.www.http.HttpClient.openServer(HttpClient.java:432) at sun.net.www.http.HttpClient.openServer(HttpClient.java:527) at sun.net.www.http.HttpClient.<init>(HttpClient.java:211) at sun.net.www.http.HttpClient.New(HttpClient.java:308) at sun.net.www.http.HttpClient.New(HttpClient.java:326) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300) at org.jasig.cas.client.util.CommonUtils.getResponseFromServer(CommonUtils.java:476) at org.jasig.cas.client.validation.AbstractCasProtocolUrlBasedTicketValidator.retrieveResponseFromServer(AbstractCasProtocolUrlBasedTicketValidator.java:41) at org.jasig.cas.client.validation.AbstractUrlBasedTicketValidator.validate(AbstractUrlBasedTicketValidator.java:193) at org.springframework.security.cas.authentication.CasAuthenticationProvider.authenticateNow(CasAuthenticationProvider.java:158) at org.springframework.security.cas.authentication.CasAuthenticationProvider.authenticate(CasAuthenticationProvider.java:143) at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:174) at org.springframework.security.cas.web.CasAuthenticationFilter.attemptAuthentication(CasAuthenticationFilter.java:270) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:97) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:744)

CloseableHttpClient 4.5.2如何设置等待超时?

CloseableHttpClient 4.5.2中执行response = httpClient.execute(httpPost); 没有任何的等待效果,直接返回无连接,如果我想让他保持请求30秒是否可以? ``` RequestConfig defaultRequestConfig = RequestConfig.custom(). setConnectTimeout(30000).setConnectionRequestTimeout(30000) .setSocketTimeout(30000).build(); // CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build(); CloseableHttpResponse response = null; String resultString = ""; HttpPost httpPost = new HttpPost(url); StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); httpPost.setEntity(entity); httpPost.setConfig(defaultRequestConfig); String uuid=UuidUtil.getuuid(); PgmsDao pgms=new PgmsDao(); LoginUI login=(LoginUI) FacesUtil.getSessionMapValue("loginUI"); String netid=login.getLdapuser().getNetid(); String request_user=login.getLdapuser().getName(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String request_date = sdf.format(new Date()); Map<String,String> request_map=(Map)new JSONObject().fromObject(json); String action=request_map.get("action"); response = httpClient.execute(httpPost); resultString = EntityUtils.toString(response.getEntity(), "utf-8"); String response_date = sdf.format(new Date()); Map<String,String>result=(Map)new JSONObject().fromObject(resultString); String status=result.get("status"); ``` 如果是别的版本也可以,请大佬指点

经常链接超时,最后没有足够缓存空间卡死了服务,求解

频繁出现connect timed out,有时出现 Address already in use,最后抛出 No buffer space available (maximum connections reached?): connect 是什么问题呢?求解。具体错误信息如下。。 java.net.SocketTimeoutException: connect timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at sun.net.NetworkClient.doConnect(NetworkClient.java:158) at sun.net.www.http.HttpClient.openServer(HttpClient.java:394) at sun.net.www.http.HttpClient.openServer(HttpClient.java:529) at sun.net.www.http.HttpClient.<init>(HttpClient.java:233) at sun.net.www.http.HttpClient.New(HttpClient.java:306) at sun.net.www.http.HttpClient.New(HttpClient.java:323) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:975) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:916) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:841) at org.wltea.web.util.SimpleHttpClient.post(SimpleHttpClient.java:75) at org.wltea.luci.client.RemoteIndexService.postQueryCommand(RemoteIndexService.java:367) at org.wltea.luci.client.RemoteIndexService.query(RemoteIndexService.java:207) at com.youboy.search.LuciSearchFk.soxggq(LuciSearchFk.java:506) at _s._gy__jsp._jspService(_gy__jsp.java:480) at com.caucho.jsp.JavaPage.service(JavaPage.java:75) at com.caucho.jsp.Page.subservice(Page.java:506) at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182) at com.caucho.server.http.Invocation.service(Invocation.java:315) at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:253) at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:170) at com.caucho.server.TcpConnection.run(TcpConnection.java:139) at java.lang.Thread.run(Thread.java:662) java.net.BindException: Address already in use: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at sun.net.NetworkClient.doConnect(NetworkClient.java:158) at sun.net.www.http.HttpClient.openServer(HttpClient.java:394) at sun.net.www.http.HttpClient.openServer(HttpClient.java:529) at sun.net.www.http.HttpClient.<init>(HttpClient.java:233) at sun.net.www.http.HttpClient.New(HttpClient.java:306) at sun.net.www.http.HttpClient.New(HttpClient.java:323) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:975) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:916) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:841) at org.wltea.web.util.SimpleHttpClient.post(SimpleHttpClient.java:75) at org.wltea.luci.client.RemoteIndexService.postQueryCommand(RemoteIndexService.java:367) at org.wltea.luci.client.RemoteIndexService.query(RemoteIndexService.java:223) at com.youboy.search.LuciSearchFk.soxgc(LuciSearchFk.java:393) at _s._gy__jsp._jspService(_gy__jsp.java:305) at com.caucho.jsp.JavaPage.service(JavaPage.java:75) at com.caucho.jsp.Page.subservice(Page.java:506) at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182) at com.caucho.server.http.Invocation.service(Invocation.java:315) at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:253) at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:170) at com.caucho.server.TcpConnection.run(TcpConnection.java:139) at java.lang.Thread.run(Thread.java:662)

Java获取http请求返回json格式数据异常

java.net.SocketTimeoutException: connect timed out at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.<init>(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) at com.elan.webservers.HttpRequestUtil.getHttp(HttpRequestUtil.java:64) at com.elan.webservers.HttpRequestUtil.main(HttpRequestUtil.java:19) 一直提示连接超时, 请问下有什么解决的方法么? // 开始连接请求 conn.connect(); //这行为异常提示行

linux下使用httpclient的http的put请求,发送json数据一直有错误

linux系统中使用curl工具发送http的put请求可以访问到web服务器的数据,其中curl的命令如下: curl -v --basic -u admin:public -k http://localhost:8080/api/v2/nodes/emq@127.0.0.1/plugins/emqx_recon -X PUT -i -H "Conten t-Type:application/json" -d '{"active":"true"}' 使用此命令可以有反馈的json结果,表示已经处理。 而在linux下开发环境eclipse使用httpclient发送http的put请求,数据是json数据,却一直报错,不清楚什么原因,贴上代码: public String doPutMethod(String host, int port, String URI,String stringJson){ if (closeableHttpClient == null) { // createCloseableHttpClient(); createCloseableHttpClientWithBasicAuth(); } String result = ""; HttpPut httpPut = null; HttpResponse httpResponse = null; HttpEntity entity = null; httpPut = new HttpPut("http://" + host + ":" + port + "/" + URI); //设置header httpPut.setHeader("Content-Type", "application/json;charset=UTF-8"); httpPut.setHeader("Accept", "application/json"); StringEntity stringEntity = null; stringEntity = new StringEntity(stringJson,ContentType.APPLICATION_JSON); stringEntity.setContentEncoding("UTF-8"); System.out.println(stringEntity.getContentType()); System.out.println(stringEntity.getContentEncoding()); try { System.out.println(EntityUtils.toString(stringEntity)); } catch (ParseException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } httpPut.setEntity(stringEntity); try { httpResponse = closeableHttpClient.execute(httpPut); entity = httpResponse.getEntity(); if (entity != null) { result = EntityUtils.toString(entity); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { httpPut.releaseConnection(); } return result; } public static void main(String args[]) { String host = "localhost"; int port = 8080; HttpClientWithBasicAuth httpClient = new HttpClientWithBasicAuth(); //test httpPutMethod String URI = "api/v2/nodes/emq@127.0.0.1/plugins/emq_auth_clientid"; String str = "{\"active\":\"true\"}"; String result = httpClient.doPutMethod(host, port, URI, str); System.out.println(result); }

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

华为初面+综合面试(Java技术面)附上面试题

华为面试整体流程大致分为笔试,性格测试,面试,综合面试,回学校等结果。笔试来说,华为的难度较中等,选择题难度和网易腾讯差不多。最后的代码题,相比下来就简单很多,一共3道题目,前2题很容易就AC,题目已经记不太清楚,不过难度确实不大。最后一题最后提交的代码过了75%的样例,一直没有发现剩下的25%可能存在什么坑。 笔试部分太久远,我就不怎么回忆了。直接将面试。 面试 如果说腾讯的面试是挥金如土...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

win10暴力查看wifi密码

刚才邻居打了个电话说:喂小灰,你家wifi的密码是多少,我怎么连不上了。 我。。。 我也忘了哎,就找到了一个好办法,分享给大家: 第一种情况:已经连接上的wifi,怎么知道密码? 打开:控制面板\网络和 Internet\网络连接 然后右击wifi连接的无线网卡,选择状态 然后像下图一样: 第二种情况:前提是我不知道啊,但是我以前知道密码。 此时可以利用dos命令了 1、利用netsh wlan...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

!大部分程序员只会写3年代码

如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

HTTP与HTTPS的区别

面试官问HTTP与HTTPS的区别,我这样回答让他竖起大拇指!

程序员毕业去大公司好还是小公司好?

虽然大公司并不是人人都能进,但我仍建议还未毕业的同学,尽力地通过校招向大公司挤,但凡挤进去,你这一生会容易很多。 大公司哪里好?没能进大公司怎么办?答案都在这里了,记得帮我点赞哦。 目录: 技术氛围 内部晋升与跳槽 啥也没学会,公司倒闭了? 不同的人脉圈,注定会有不同的结果 没能去大厂怎么办? 一、技术氛围 纵观整个程序员技术领域,哪个在行业有所名气的大牛,不是在大厂? 而且众所...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

美团面试,问了ThreadLocal原理,这个回答让我通过了

他想都想不到,ThreadLocal我烂熟于心

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

立即提问
相关内容推荐