1

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

注意:我已将我的 URL 链接更改为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;         
    }    
4

0 回答 0