Java CookiePolicy ACCEPT_ORIGINAL_SERVER

Syntax

CookiePolicy.ACCEPT_ORIGINAL_SERVER has the following syntax.

static final CookiePolicy ACCEPT_ORIGINAL_SERVER

Example

In the following code shows how to use CookiePolicy.ACCEPT_ORIGINAL_SERVER field.


//from w  w w.  j  a v  a  2  s  . c om
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.HttpCookie;
import java.net.URL;
import java.util.List;

public class Main {
  public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();

    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
      System.out.println("Name = " + cookie.getName());
      System.out.println("Value = " + cookie.getValue());
      System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
      System.out.println("Path = " + cookie.getPath());
      System.out.println();
    }
  }
}




















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder