对于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错误的更多相关文章

  1. org.apache.http.ProtocolException: Target host is not specified

    对于httpClient4.3访问指定页面,可以从下面的demo抽取方法使用. 注意:对于URL必须使用 http://开始,否则会有如下报错信息: Caused by: org.apache.htt ...

  2. ORA-12545:Connect failed beacuse target host or object does not exist

    更换计算机名,重新启动系统后 oracle 的监听器就无法正常启动, 总是提示ORA-12545:Connect failed beacuse target host or object does n ...

  3. ORA-12545: Connect failed because target host or object does not exist

    [oracle@ybdbtest oradata]$ sqlplus /nolog SQL*Plus: Release 9.2.0.4.0 - Production on Thu Jun 26 10: ...

  4. Android开发中与服务器交互时,遇到java.io.IOException: Target host must not be null的问题

    当我遇到这个问题的时候,也在网上查找好半天.找到了一个和这个问题很类似的问题——java.lang.IllegalStateException: Target host must not be nul ...

  5. TNS-12545: Connect failed because target host or object does not exist

    问题描述 $ lsnrctl startLSNRCTL for Linux: Version 12.1.0.2.0 - Production on 26-JUL-2017 09:53:42Copyri ...

  6. ArcServer 10.0 “No Content”、“Server Host Cannot be null” 错误

    问题一:"No Content" 问题描述: 在输入服务地址时:http://192.168.1.180/arcgis/services   结果出现下面的错误:   解决办法: ...

  7. 登录ssh时Host key verification failed错误

    工作中总是测试不同的路由设备, 路由器的ip都是 192.168.111.1 ,ssh登录的时候总是出现这个错误. macos上,错误如下 spawn ssh -p 22 root@192.168.1 ...

  8. Linux REMOTE HOST IDENTIFICATION HAS CHANGED错误解决方法

    http://linuxme.blog.51cto.com/1850814/375752       WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED解决 ...

  9. "flash download failed - Target dll has been cancelled"错误解决办法

    在用mdk通过stlink烧写官方例程到stm32f429I discovery时,烧写了十来个程序都没问题,突然在烧写一个程序时, 弹出了“flash download failed - Targe ...

随机推荐

  1. 【转】【C#】无边框窗体移动的三种方法

    1. 重写WndProc protected override void WndProc(ref Message m) { const int WM_NCHITTEST = 0x84; const i ...

  2. Python urllib2 模块学习笔记

    2015.3.6  urllib2的使用方法大致如下 # 定制Handler处理函数 opener = urllib2.build_opener(ProxyHandler, HTTPHandler) ...

  3. amazon RequestReport

    _GET_SELLER_FEEDBACK_DATA_        MarketplaceIdList 这此字段必填,否则无法取到报告

  4. ScrollBox 响应鼠标滚轮和ComboBox禁止滚动

    procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: ...

  5. KM3

    本科:读完一本书,知道book里讲的是什么,带有知识吸收: 硕士:读完一本书,知道book里的内容,而且还能发现相关的问题,带有知识的思考: 博士:读完一本书,知道book里的内容,而且还能发现相关的 ...

  6. mac 下 sphinx + mysql + php 实现全文搜索(xampp)(4)php api 解析

    1:function GetLastError()  // 假如报错的话,会输出报错信息 2:function GetLastWarning ()// 输出 警告信息 3:function SetSe ...

  7. C#基础及记忆概念

    在C#中,你给一个方法传输值类型参数时,实际上是使用的这个参数的一个副本,就是将原来的变量复制一份,然后传给一个方法,让其进行操作.所以在方法内部对参数的修改等不会对原来的参数造成影响(这个其实就是值 ...

  8. BZOJ3404: [Usaco2009 Open]Cow Digit Game又见数字游戏

    3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 47  Solved ...

  9. PAT-乙级-1027. 打印沙漏(20)

    1027. 打印沙漏(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求你写个程序把给定的符号打印成 ...

  10. leetcode5 Implement strstr() 实现strstr函数功能

    Implement strstr() 实现strstr函数功能 whowhoha@outlook.com Question: Implement strstr(). Returns the index ...