Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Even I am getting the same exception i.e java.net.ConnectException: Connection timed out: connect if I am not adding the proxy &amp; port in your code. </p> <pre><code>java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source) at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.protocol.https.HttpsClient.&lt;init&gt;(Unknown Source) at sun.net.www.protocol.https.HttpsClient.New(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source) at edu.sandip.TestURLConnection.main(TestURLConnection.java:23) </code></pre> <p>This exception you are getting because you are executing the code on your organization behind your organization proxy.</p> <p>please use the below modified code. you will get the 200 OK as responseCode.</p> <pre><code> import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import javax.net.ssl.HttpsURLConnection; public class TestURLConnection { /** * @param args */ public static void main(String[] args) { try{ URL url = new URL("https://www.google.com/"); System.setProperty("https.proxyHost", "XXX.XXX.XXX.XX"); System.setProperty("https.proxyPort", "80"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); //HttpsURLConnection connection = (HttpsURLConnection)url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); int code = connection.getResponseCode(); System.out.println("code: "+code); } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p>NOTE: 1. You need to get the proxyHost IP from your organization network admin. 2. You should use HttpsURLConnection for accessing https URL.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload