Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.apache.http.ProtocolException:未指定目标主机_Java_Httpclient_Httpresponse_Apache Httpclient 4.x - Fatal编程技术网

Java org.apache.http.ProtocolException:未指定目标主机

Java org.apache.http.ProtocolException:未指定目标主机,java,httpclient,httpresponse,apache-httpclient-4.x,Java,Httpclient,Httpresponse,Apache Httpclient 4.x,我已经编写了一个简单的httprequest/response代码,下面是一个错误。我在类路径中引用了httpclient、httpcore、通用编解码器和通用日志。我对java非常陌生,不知道这里发生了什么。请帮帮我 代码: 错误: Exception in thread "main" org.apache.http.client.ClientProtocolException at org.apache.http.impl.client.InternalHttpClient.doEx

我已经编写了一个简单的httprequest/response代码,下面是一个错误。我在类路径中引用了httpclient、httpcore、通用编解码器和通用日志。我对java非常陌生,不知道这里发生了什么。请帮帮我

代码:

错误:

Exception in thread "main" org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
    at UnshorteningUrl.main(UnshorteningUrl.java:26)
Caused by: org.apache.http.ProtocolException: Target host is not specified
    at org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:69)
    at org.apache.http.impl.client.InternalHttpClient.determineRoute(InternalHttpClient.java:124)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:183)
    ... 4 more

错误消息有点误导人。您提供了一个不代表完整URI的值

request = new HttpGet("trib.me/1lBFzSi");
request = new HttpGet("http://trib.me/1lBFzSi");
它缺少一个协议

只需提供一个完整的URI

request = new HttpGet("trib.me/1lBFzSi");
request = new HttpGet("http://trib.me/1lBFzSi");

此错误可能是由错误的url引起的。 检查url:

  • 协议缺失
  • url参数编码
    在我的情况下,我在Begging添加了以下内容: 请求=新的HttpGet(“/trib.me/1lBFzSi”)