我在搜索我的网站上具有自动完成/提前输入功能。我看到他们有时是一个例外。我们正在使用代理服务器。
org.apache.http.conn.HttpHostConnectException: Connection to http://proxy.xyz.com:60 refused at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:159) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554) at com.xxx.dd.sone.integration.SearchDAO.getJSONData(SearchDAO.java:60) at com.xxx.dd.sone.integration.SearchDAO.searchAutoCompleteResults(SearchDAO.java:560) at com.xxx.dd.sone.presentation.util.SearchAutoCompleteUtil.doGet(SearchAutoCompleteUtil.java:26) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at javax.servlet.http.HttpServlet.service(HttpServlet.java:845) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:352) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:236) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254) at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57) at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1512) at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255) at weblogic.work.ExecuteRequestAdapter.execute(ExecuteRequestAdapter.java:22) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:147) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:119)
引起原因:java.net.ConnectException:连接被拒绝
这是我的编码方式
public HashMap<String, Object> getJSONData(String url)throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); try { HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSoTimeout(params, 10000); } catch (Exception e) { e.printStackTrace(); throw e; } HttpHost proxy = new HttpHost(proxy.xyz.com, 60); ConnRouteParams.setDefaultProxy(params, proxy); URI uri; InputStream data = null; uri = new URI(url); HttpGet method = new HttpGet(uri); HttpResponse response=null; try { response = httpClient.execute(method); }catch(Exception e) { e.printStackTrace(); throw e; } data = response.getEntity().getContent(); Reader r = new InputStreamReader(data); HashMap<String, Object> jsonObj = (HashMap<String, Object>) GenericJSONUtil.fromJson(r); return jsonObj; }
谁能告诉我为什么我只在某个时候得到这个例外?是否可能是由于从Android应用程序发出搜索请求而导致此异常,因为我们的网站不支持从android应用程序发出请求
当您尝试打开与IP地址/端口的TCP连接,而当前没有任何侦听连接的情况时,会发生“拒绝连接”错误。如果没有监听,则服务器端的操作系统“拒绝”连接。
如果这是间歇性发生,则最可能的解释是(IMO):
当我们从Android应用程序发出搜索请求时可能会导致此异常,因为我们的网站不支持从android应用程序发出请求。
似乎不太可能。您说“连接被拒绝”异常消息表示拒绝连接的是代理,而不是服务器。此外,如果服务器不处理某些类型的请求,它仍必须接受TCP连接以找出请求的内容,然后才能拒绝该请求。
1-例如,可能是将DNS名称轮流解析为不同IP地址的DNS。也可以是基于IP的负载平衡器。