Hi,

Please chech this:

private boolean CheckInternetConnection
 {
        Log.d(TAG, "CheckInternetConnection() ");
        try
        {
            URL url = new URL("http://www.google.com/";);            // ...
            HttpURLConnection urlc = (HttpURLConnection)
url.openConnection();
            urlc.setRequestProperty("User-Agent", "My Android IMservice");
            urlc.setRequestProperty("Connection", "close");
            urlc.setConnectTimeout(1000 * 10); // mTimeout is in seconds
            urlc.connect();
            if (urlc.getResponseCode() == 200)
            {
                return true;
            }
        }
        catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return false;

}

On Sat, May 15, 2010 at 11:51 PM, Arkaitz Jimenez <arkai...@gmail.com>wrote:

> Hi all,
> I think I'm experiencing the same as
> http://groups.google.com/group/android-developers/msg/9d37d64aad0ee357
> This is Android 1.5 SDK.
> I happen to call several times below code(which is in a method) with
> the same url and it fails intermitently.
> When it fails, there is no exception, the stream is empty so the
> readConnection fails, and getResponseCode returns -1.
> Global caching is disabled, setDefaultUseCaches(false);
>
> Any idea on how can I workaround this?
>
>    HttpURLConnection connection = null;
>        try {
>            URL url = new URL(this.url);
>            connection = (HttpURLConnection) url.openConnection();
>            connection.setRequestProperty("Authorization", "basic " +
> Base64Coder.encodeString(user + ":" + password));
>            connection.setRequestProperty("User-Agent", userAgent);
>            connection.connect();
>
>            readConnection(connection.getInputStream());
>
>            connection.disconnect();
>        } catch (IOException ex) {
>                   reportException(ex, connection.getResponseCode())
>        } catch (ParserException ex) {
>                   reportException(ex, connection.getResponseCode())
>        }
>
> Thanks
>
> Arkaitz
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Thank & Regards
Peeyush Varshney

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to