关于java.net.UnknownHostException: Unable to resolve host "xx": No address associated with hostname
来源:互联网 发布:seo关键词优化怎么做 编辑:程序博客网 时间:2024/06/06 03:36
关于java.net.UnknownHostException: Unable to resolve host “xx”: No address associated with hostname
前段时间在使用Asynchttpclient这个网络请求框架的时候,遇到过标题的这个错误,翻墙找了挺久,终于解决了,下面贴出解决办法。
1.我的需求是POST Json数据到服务器,然后返回Json数据(下面是Asynchttpclient post json的方法)
AsyncHttpClient client=new AsyncHttpClient();
client.setTimeout(10000);
client.addHeader(“content-type”,”application/json;charset=UTF-8”);
//方法1:使用Gson把实体类转成Json
// Gson gson=new Gson();
// String object = gson.toJson(new HttpEntity());
// Log.i(TAG,object);
StringEntity stringEntity = null;
try {
//方法2: 自己手写Json
JSONObject jsonObject=new JSONObject();
JSONObject jsonHeader=new JSONObject();
jsonHeader.put(“code”,”R1002”);
JSONObject jsonBody=new JSONObject();
jsonBody.put(“companyCode”,”beiqixinnengyuan”);
jsonBody.put(“username”,”ryan”);
jsonBody.put(“imei”,”86130402042171”);
jsonObject.put(“body”, jsonBody);
jsonObject.put(“header”, jsonHeader);
Log.i(TAG,jsonObject.toString());
stringEntity = new StringEntity(jsonObject.toString());
stringEntity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
“application/json;charset=UTF-8”));
}catch (Exception e){
e.printStackTrace();
}
client.post(getApplicationContext(), URL, stringEntity, “application/json;charset=UTF-8”,new JsonHttpResponseHandler(){
//重写成功和失败的方法
});
2.然后写完就提示我java.net.UnknownHostException: Unable to resolve host “xx”: No address associated with hostname;于是百度了一下,百度给了几个答案(Manifest权限,是否联网等)都解决不了我的问题,然后翻墙去谷歌了一把, Asynchttpclient的github托管地址里有人提出是因为使用最新版的asynchttpclient-1.4.9.jar的问题,然后我下了个1.4.4的jar试了一下,果然是jar包的问题。
3.这个bug给我提了一个醒,所谓的开源,就是大家都能去共享这个东西,也希望这个东西可以做的更好,所以bug是在不断使用中发现的,同时,我自己遇到这个坑,也希望后面遇到这个坑的人不要浪费太多时间。
- 关于java.net.UnknownHostException: Unable to resolve host "xx": No address associated with hostname
- java.net.UnknownHostException: Unable to resolve host "xxx": No address associated with hostname
- Unable to resolve host : No address associated with hostname
- Unable to resolve host : No address associated with hostname
- android java.net.UnknownHostException: Unable to resolve host "...": No address associated 错误
- android java.net.UnknownHostException: Unable to resolve host "...": No address associated 错误
- android java.net.UnknownHostException: Unable to resolve host "...": No address associated 错误
- android java.net.UnknownHostException: Unable to resolve host "...": No address associated 错误
- android java.net.UnknownHostException: Unable to resolve host "...": No address associated 错误
- 解决android上java.net.UnknownHostException: Unable to resolve host "xxxx": No address associated wit
- android java.net.UnknownHostException: Unable to resolve host "...": No address associated 错误
- android java.net.UnknownHostException: Unable to resolve host "...": No address associated
- java.net.UnknownHostException: Unable to resolve host "images.liqucn.com": No address associated wit
- java.net.UnknownHostException: Unable to resolve host "api1.51zhenghao.cn": No address associated w
- okhttp Unable to resolve host “<host-name>”: No address associated with hostname的解决办法
- Unable to resolve host “<insert URL here>” No address associated with hostname
- IOException Unable to resolve host "api.linkface.cn": No address associated with hostname
- Unable to resolve host "api1.51zhenghao.cn": No address associated with hostname
- 信号量与互斥锁
- Android startActivityForResult与singleTask
- 百度社区超级版主讲解Dedecms网站移动化seo
- remap的困惑说明
- EF模式下数据库的表一定要设置主键
- 关于java.net.UnknownHostException: Unable to resolve host "xx": No address associated with hostname
- Shell脚本编程学习笔记
- com编程快速入门
- Xcode 断点调试获取值为nil的问题
- C++ 的引用
- Cocoapods Undefined symbols for architecture armv7s\arm64\x86_64
- 编写shell脚本unload表格里的内容到指定文件里
- 两台Linux的通信(文件传输)
- Markup类 xml文件操作