HttpClient:Target host must not be null, or set in parameters

来源:互联网 发布:楠木正成 知乎 编辑:程序博客网 时间:2024/05/16 03:22
HttpClient client = new DefaultHttpClient();  
HttpGet get = new HttpGet("www.baidu.com");  
HttpResponse response = client.execute(get); 
抛出异常:Target host must not be null, or set in parameters
原因是:url写法错误,需要加上http://
解决办法:将" www.baidu.com "改为"http://www.baidu.com"
0 0
原创粉丝点击