美文网首页
之Target host is not sp

之Target host is not sp

作者: o惜乐o | 来源:发表于2018-05-15 09:33 被阅读0次

    本文介绍了出现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,出问题的原因主要在新旧数据库替换时,已添加新的表结构,却遗漏了插入数据的代码.所以,开发中还是要多些谨慎细心.

    CSDN

    Java常见问题之Target host is not specified

    相关文章

      网友评论

          本文标题:之Target host is not sp

          本文链接:https://www.haomeiwen.com/subject/efxqdftx.html