java.net.SocketException:在期刊http get,android上无法访问网络

时间:2011-08-26 03:25:32

标签: android sockets

我尝试每隔30秒使用http get方法获取设备设置信息,我总是在我的Android设备上成功获得两个http请求/响应,

08-25 19:42:47.789: DEBUG/LitDebug(25907): RestClient: GET, URL = http://www.LockItTight.com/devices/10627.json?device_key=A0000028F3CA5A
08-25 19:42:48.219: DEBUG/LitDebug(25907): HTTP/1.1 200 OK

但是我将在以下http请求/响应中获得以下异常:

08-25 19:43:32.789: DEBUG/LitDebug(25907): RestClient: GET, URL = http://www.LockItTight.com/devices/10627.json?device_key=A0000028F3CA5A
08-25 19:43:32.799: DEBUG/LitDebug(25907): RestClient: GET, java.net.SocketException: Network unreachable

我在SDK上没有这个问题,这是我的代码片段:

`

 try {       
        // Prepare a request object
        HttpGet request = new HttpGet("http://www.LockItTight.com/devices/10627.json?device_key=A0000028F3CA5A");

        // Execute HTTP Get request
        HttpResponse response = httpClient.execute(request);
        int responseCode = response.getStatusLine().getStatusCode();
        Logger.log("RestClient: Get, responseCode = " + responseCode);          

    } catch (ClientProtocolException e) {
        Logger.log("RestClient: GET, " + e.toString());
    } catch (IOException e) {
        Logger.log("RestClient: GET, " + e.toString());
    } catch (Exception e) {
        Logger.log("RestClient: GET, " + e.toString());
    }

` 有人可以告诉我为什么我的代码在SDK中成功但在设备上失败了吗?

0 个答案:

没有答案