我在HTTPResponseCache
的实施方面面临一个问题。该实现在Galaxy S2设备中的Android 4.0.3
版本中非常有效,其中相同的代码对于使用Android 4.0.4版本的Galaxy S3设备不起作用。
在阅读InputStream
时,它会抛出在飞行模式下找不到的异常URL。
如果某个机构有想法,请分享。
感谢。
请在Galaxy S3上发送请求时找到和平代码和异常。
private void executeGETRequest(){
InputStream inStream = null;
String result = "";
try{
URL url = new URL("http://example.com/target");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setUseCaches(true);
urlConnection.addRequestProperty("Client-Identity", getHeader());
urlConnection.addRequestProperty("Cache-Control", "max-stale=" + NetworkConstants.MAX_STALE_TIME);
urlConnection.setRequestProperty("Accept", "application/json");
inStream = urlConnection.getInputStream();//Point where the error occur
if(null != inStream){
result = convertStreamInToString(inStream);
//result output
}
result = null;
inStream.close();
inStream = null;
}catch(Exception e){
e.printstack();
}
}
,例外是
:- 10-22 14:10:35.110: W/System.err(6194): java.net.UnknownHostException: Unable to resolve host "www.example.com": No address associated with hostname
10-22 14:10:35.110: W/System.err(6194): at java.net.InetAddress.lookupHostByName(InetAddress.java:400)
10-22 14:10:35.110: W/System.err(6194): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
10-22 14:10:35.110: W/System.err(6194): at java.net.InetAddress.getAllByName(InetAddress.java:220)
10-22 14:10:35.110: W/System.err(6194): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
10-22 14:10:35.110: W/System.err(6194): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
10-22 14:10:35.115: W/System.err(6194): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
10-22 14:10:35.115: W/System.err(6194): at com.network.NetworkManager.executeGETRequest(NetworkManager.java:257)
10-22 14:10:35.115: W/System.err(6194): at com.network.NetworkManager.processRequest(NetworkManager.java:325)
10-22 14:10:35.115: W/System.err(6194): at com.network.NetworkManager.access$0(NetworkManager.java:307)
10-22 14:10:35.115: W/System.err(6194): at com.network.NetworkManager$1.run(NetworkManager.java:408)
10-22 14:10:35.115: W/System.err(6194): at java.lang.Thread.run(Thread.java:856)
由于