sRaj
sRaj

Reputation: 105

HttpsURLConnection status code 302 when establishing a connection

I am trying an example on httpsURLConnection,I get the following exception

Status code: 302

ejava.lang.IllegalStateException: connection not yet open

Following is the code snippet :

  private static String url_s = "https://java.sun.com:443" ;

   URL url = new URL(url_s) ;
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection() ;
        conn.setDoInput(true);
        conn.setRequestMethod("GET") ;
        conn.connect() ;

Upvotes: 0

Views: 623

Answers (1)

Nazgul
Nazgul

Reputation: 1902

You need to read up a bit about HTTP protocol first if you really wanna try your hands at direct client calling.

302 is temporary redirect header which is sent back from the server. The response has another header named 'Location' whose value is a URL to which the server wants you to hit next. Browsers handle this automatically so you dont see a wait thing.

But if you want to do it yourself be sure ot handle all 301, 302 situations like these.

Best Of Luck.

Upvotes: 2

Related Questions