Check if Internet connection is available through proxy
<p>I'm trying to check if Internet connection is available on android devices but my internet connection requires a proxy to reach internet.</p>

<p>This is my code:</p>

<pre><code>URL myurl = new URL("http://www.google.com");
HttpURLConnection connection;
InetSocketAddress proxyInet = new InetSocketAddress(session.getUrlProxy(),session.getPortProxy());
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyInet);
connection = (HttpURLConnection)myurl.openConnection(proxy);
connection.setConnectTimeout(2000);
connection.setReadTimeout(2000);
int responseCode = -1;
responseCode = connection.getResponseCode();
                if (responseCode == HttpURLConnection.HTTP_OK) {
                      connected= true;
                      connection.disconnect();
                }
                else {
                    connection.disconnect();
                }
</code></pre>

<p>This code returns this exception message:</p>

<pre><code>java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
04-28 09:33:38.115 25512-25672/com.asde.minimental W/System.err:     at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:545)
04-28 09:33:38.119 25512-25672/com.asde.minimental W/System.err:     at libcore.io.IoBridge.recvfrom(IoBridge.java:509)
04-28 09:33:38.122 25512-25672/com.asde.minimental W/System.err:     at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
04-28 09:33:38.122 25512-25672/com.asde.minimental W/System.err:     at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
04-28 09:33:38.125 25512-25672/com.asde.minimental W/System.err:     at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
04-28 09:33:38.129 25512-25672/com.asde.minimental W/System.err:     at java.io.InputStream.read(InputStream.java:163)
04-28 09:33:38.135 25512-25672/com.asde.minimental W/System.err:     at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142)
04-28 09:33:38.139 25512-25672/com.asde.minimental W/System.err:     at java.io.BufferedInputStream.read(BufferedInputStream.java:227)
04-28 09:33:38.142 25512-25672/com.asde.minimental W/System.err:     at libcore.io.Streams.readAsciiLine(Streams.java:201)
04-28 09:33:38.145 25512-25672/com.asde.minimental W/System.err:     at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560)
04-28 09:33:38.149 25512-25672/com.asde.minimental W/System.err:     at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813)
04-28 09:33:38.149 25512-25672/com.asde.minimental W/System.err:     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
04-28 09:33:38.149 25512-25672/com.asde.minimental W/System.err:     at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
04-28 09:33:38.152 25512-25672/com.asde.minimental W/System.err:     at com.asde.minimental.utilities.Utils.isInternetConn(Utils.java:283)
04-28 09:33:38.152 25512-25672/com.asde.minimental W/System.err:     at com.asde.minimental.net.AsyncUpdater.doInBackground(AsyncUpdater.java:58)
04-28 09:33:38.155 25512-25672/com.asde.minimental W/System.err:     at com.asde.minimental.net.AsyncUpdater.doInBackground(AsyncUpdater.java:30)
04-28 09:33:38.155 25512-25672/com.asde.minimental W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-28 09:33:38.159 25512-25672/com.asde.minimental W/System.err:     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-28 09:33:38.162 25512-25672/com.asde.minimental W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-28 09:33:38.165 25512-25672/com.asde.minimental W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-28 09:33:38.165 25512-25672/com.asde.minimental W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-28 09:33:38.169 25512-25672/com.asde.minimental W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-28 09:33:38.175 25512-25672/com.asde.minimental W/System.err:     at java.lang.Thread.run(Thread.java:856)
04-28 09:33:38.179 25512-25672/com.asde.minimental W/System.err: Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
04-28 09:33:38.182 25512-25672/com.asde.minimental W/System.err:     at libcore.io.Posix.recvfromBytes(Native Method)
04-28 09:33:38.185 25512-25672/com.asde.minimental W/System.err:     at libcore.io.Posix.recvfrom(Posix.java:132)
04-28 09:33:38.185 25512-25672/com.asde.minimental W/System.err:     at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
04-28 09:33:38.185 25512-25672/com.asde.minimental W/System.err:     at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
04-28 09:33:38.185 25512-25672/com.asde.minimental W/System.err:    ... 21 more
</code></pre>

<p>This code without proxy runs fine</p>

<pre><code>connection = (HttpURLConnection)myurl.openConnection();
</code></pre>

<p>What would be wrong?</p>

<p>Thanks</p>

<p><strong>EDIT1:</strong> If I try with <a href="https://stackoverflow.com/">https://stackoverflow.com/</a> it works correctly. The problem seems to be with the google server which is reaching the request</p>