从Android设备连接到服务器时的连接超时

时间:2013-03-31 14:28:44

标签: android

我正在尝试从我的Android手机连接到我的服务器。但我得到了超时连接错误。可能是什么原因?

注意:我已将我的网址链接更改为http://google.com并且运作良好,所以请提供建议。

我的代码是

public static boolean bHasInternetAccess() 
    {  
        InputStream in=null;
        int response=-1;
        boolean bHasInternet=true;

        try
        {
            URL url=new URL("http://192.168.1.100/AWS.asmx/dtTickets?sTech_ID=-99");
            URLConnection conn= url.openConnection();
            if (!(conn instanceof HttpURLConnection))
            {
                bHasInternet=false;
            }
            HttpURLConnection httpConn=(HttpURLConnection)conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.setConnectTimeout(15000); 
            httpConn.connect();
            response=httpConn.getResponseCode();

            if (response==HttpURLConnection.HTTP_OK)
            {
                in=httpConn.getInputStream();
            }
        }
        catch (Exception ex)
        {
            bHasInternet=false;
        }
        if (in==null) {
            bHasInternet=false;
        }
        return bHasInternet;         
    }    

0 个答案:

没有答案