Target host is not specified错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Target host is not specified错误相关的知识,希望对你有一定的参考价值。

对于httpClient4.3访问指定页面,可以从下面的demo抽取方法使用。

注意:对于URL必须使用 http://开始,否则会有如下报错信息:

或者在设置cookie时带上domain: cookie.setDomain(domain);

或者:cookie.setDomain("0.0.0.0");

 

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)
    ... 5 more

demo代码:

public class ClientWithResponseHandler {
public static String url = "http://www.baidu.com";
    public final static void main(String[] args) throws Exception {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            HttpGet httpget = new HttpGet(url);

            System.out.println("Executing request " + httpget.getRequestLine());

            // Create a custom response handler
            ResponseHandler<String> responseHandler = new ResponseHandler<String>() {

                public String handleResponse(
                        final HttpResponse response) throws ClientProtocolException, IOException {
                    int status = response.getStatusLine().getStatusCode();
                    if (status >= 200 && status < 300) {
                        HttpEntity entity = response.getEntity();
                        return entity != null ? EntityUtils.toString(entity) : null;
                    } else {
                        throw new ClientProtocolException("Unexpected response status: " + status);
                    }
                }

            };
            String responseBody = httpclient.execute(httpget, responseHandler);
            System.out.println("----------------------------------------");
            System.out.println(responseBody);
        } finally {
            httpclient.close();
        }
    }

以上是关于Target host is not specified错误的主要内容,如果未能解决你的问题,请参考以下文章

Cannot start compilation: the output path is not specified for module "HelloWorld". Specif

cp Target is not a directory

尝试在 Windows 上使用 cp 命令时获取 cp: target 'target.yml' is not a directory

Target runtime Apache Tomcat v7.0 is not defined.

Target runtime Apache Tomcat 6.0 is not defined 解决方法(转)

Target runtime Apache Tomcat v8.0 is not defined