org.apache.http.client.ClientProtocolException: URI does not specify a valid host name

org.apache.http.client.ClientProtocolException: URI does not specify a valid host name: xxxx.com.cn:8080/xxxxx/Detail

e.printStackTrace():org.apache.http.client.ClientProtocolException: URI does not specify a valid host name: stltfvir-inter.yto56.com.cn:8089/stltffvirtualbillauto/searchDetail
    at org.apache.http.impl.client.CloseableHttpClient.determineTarget(CloseableHttpClient.java:94)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
    at com.yto.monitor.web.util.HttpClientUtil.httpPostWithJson(HttpClientUtil.java:63)
    at com.yto.monitor.web.service.impl.financeServiceImpl.FinanceServiceImpl.searchDetail(FinanceServiceImpl.java:66)
    at com.yto.monitor.web.controller.FinanceController.searchDetail(FinanceController.java:27)
    at com.yto.monitor.web.controller.FinanceController$$FastClassBySpringCGLIB$$ffe65ed9.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
    at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:47)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke

解决方式

我这边需要调用公司其他部门的一个详情接口,拿到数据之后做组合展示,完成开发功能之后我在测试环境一切正常,然后开始准备生产发布,然后就发生了上述错误。刚开始我以为是生产上没有能访问调用接口地址权限,后面登录到服务器ping的通,也能进入telnet。后面我尝试了解了一下这个ClientProtocolException异常信息,了解到在我们通过域名作为httpPost的请求地址时,前面必须加上http://这个协议也就是我们必须将访问的地址设置成http://xxx.xxx.com/xxx/xxx/detail这种方式去访问生产环境的域名地址。
原文地址:https://www.cnblogs.com/technical-life/p/14606453.html