Target host is not specified错误
注意:对于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错误的更多相关文章
- org.apache.http.ProtocolException: Target host is not specified
对于httpClient4.3访问指定页面,可以从下面的demo抽取方法使用. 注意:对于URL必须使用 http://开始,否则会有如下报错信息: Caused by: org.apache.htt ...
- ORA-12545:Connect failed beacuse target host or object does not exist
更换计算机名,重新启动系统后 oracle 的监听器就无法正常启动, 总是提示ORA-12545:Connect failed beacuse target host or object does n ...
- 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: ...
- Android开发中与服务器交互时,遇到java.io.IOException: Target host must not be null的问题
当我遇到这个问题的时候,也在网上查找好半天.找到了一个和这个问题很类似的问题——java.lang.IllegalStateException: Target host must not be nul ...
- 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 ...
- ArcServer 10.0 “No Content”、“Server Host Cannot be null” 错误
问题一:"No Content" 问题描述: 在输入服务地址时:http://192.168.1.180/arcgis/services 结果出现下面的错误: 解决办法: ...
- 登录ssh时Host key verification failed错误
工作中总是测试不同的路由设备, 路由器的ip都是 192.168.111.1 ,ssh登录的时候总是出现这个错误. macos上,错误如下 spawn ssh -p 22 root@192.168.1 ...
- Linux REMOTE HOST IDENTIFICATION HAS CHANGED错误解决方法
http://linuxme.blog.51cto.com/1850814/375752 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED解决 ...
- "flash download failed - Target dll has been cancelled"错误解决办法
在用mdk通过stlink烧写官方例程到stm32f429I discovery时,烧写了十来个程序都没问题,突然在烧写一个程序时, 弹出了“flash download failed - Targe ...
随机推荐
- 【转】oracle中触发器中:new和:old 的使用方法
create or replace trigger TRI_PrintTest before delete or insert or update on TEST_EXAM --触发事件 for ea ...
- grails环境搭建
关于grails,前方有大坑,入坑需谨慎. 使用grails,最好有人指点,因为有很多坑等着你去跳.如果完全是自己折腾,每前进一步都会花一些时间,且不说这些时间用来干其他事情有更多回报,光是像堵车一样 ...
- android 打开GPS的几种方式
1.在讨论打开gps的之前先看下如何检测gps的开关情况: 方式一: boolean gpsEnabled = locationManager.isProviderEnabled(LocationMa ...
- vb6-很简单的配置密码验证提示
'很简单的配置密码验证提示 Dim add As String add = Trim(InputBox("请输入配置密码", "报表配置")) If add = ...
- 一些shell脚本实例
在群里也混了不少时间了.总结一些实例 #统计QQ消息里面某个用户改名字的记录# awk -f# 聊改名字记录#特殊例子 例如#2013-11-28 9:23:56 北京-AA-Vip<12345 ...
- C++程序员笔试复习概要(一)
第8章 类和对象的创建 [内容提要] 类和对象 构造函数和析构函数 对象数组与对象指针 静态成员 友元 静态函数 虚函数 [重点与难点] 8.1 类和对象 8.1.1 类的定义 类实质上是用户 ...
- SQLite3中自增主键
SQLite清空表并将自增列归零 SQL标准中有TRUNCATE TABLE语句,用来清空表的所有内容. 但SQLite不支持这个语句.在SQLite中直接使用 DELETE FROM TableNa ...
- JS 实现取整
Js 常用数值函数(Math,parseInt)取整 1.丢弃小数部分,保留整数部分parseInt(5/2) 2.向上取整,有小数就整数部分加1Math.ceil(5/2) 3,四舍五入.Mat ...
- HttpClient抓取网页内容简单介绍
版本HttpClient3.1 1.GET方式 第一步.创建一个客户端,类似于你用浏览器打开一个网页 HttpClient httpClient = new HttpClient(); 第二步.创建一 ...
- python学习笔记27(python中sys模块的使用)
sys.argv 命令行参数List,第一个元素是程序本身路径 sys.modules.keys() 返回所有已经导入的模块列表 sys.exc_info() 获取当前正在 ...