本文介绍了出现Target host is not specified
问题的解决方式
一.bug提示如下
Caused by: org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at com.api.client.handler.NdcHandlerImpl2.getResponseAsString(NdcHandlerImpl2.java:336)
at com.api.client.handler.NdcHandlerImpl2.airShopping(NdcHandlerImpl2.java:73)
... 8 more
Caused by: org.apache.http.ProtocolException: Target host is not specified
at org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:71)
at org.apache.http.impl.client.InternalHttpClient.determineRoute(InternalHttpClient.java:125)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
... 12 more
二.分析
Target host is not specified
指目标主机未指定,因项目中使用到HttpClient
,故与HttpClient
的使用有关.
三.解决:
通过debug,问题定位在以下代码中:
HttpPost request = new HttpPost( url );
HttpResponse response = httpClient.execute(request);
查看url值为null,那问题就锁定在请求时url的值上,打开数据库,发现引用的endpoint
字段值全为null,所以,插入数据库的值即可.
四.思考
以上仅仅是一个简单的bug,出问题的原因主要在新旧数据库替换时,已添加新的表结构,却遗漏了插入数据的代码.所以,开发中还是要多些谨慎
与 细心
.
网友评论