HttpURLConnection SetInstanceFollowRedirects() Example

Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this HttpURLConnection instance.


HttpURLConnectionclass SetInstanceFollowRedirects() method example. This example shows you how to use SetInstanceFollowRedirects() method.This method Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this HttpURLConnection instance.

Here is the code:-
/* 
 * @Program that Sets whether HTTP redirects should be automatically followed 
    by this HttpURLConnection instance
 * SetInstanceFollowRedirects.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */

import java.net.*;

public class SetInstanceFollowRedirects {

    public static void main(String[] argsthrows Exception {
        URL url = new URL("http://192.168.10.211:8080");
        HttpURLConnection connection = (HttpURLConnectionurl.openConnection();
        //Returns value of HttpURLConnection's instanceFollowRedirects field.
        System.out.println("HttpURLConnection's instanceFollowRedirects: "
                +connection.getInstanceFollowRedirects());
        connection.setInstanceFollowRedirects(false);
        System.out.println("HttpURLConnection's instanceFollowRedirects: "
                +connection.getInstanceFollowRedirects());
    }
}

Output of the program:-
 HttpURLConnection's instanceFollowRedirects: true
HttpURLConnection's instanceFollowRedirects: false

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US