Although the code is not complete, it will run and will get a cookie
from the site that it connects to.

Kevin Mukhar wrote:
>
> This code is not complete. It only has enough to show getting a cookie
> and setting a cookie. Actually getting a page or sending GET or POST
> data is not shown. Replace www.server.com with the name of a server that
> sends a cookie when you access the site:
>
> import java.net.*;
> import java.io.*;
>
> public class CookieDemo {
>   private String cookie;
>
>   public static void main(String[] args) {
>     CookieDemo c = new CookieDemo();
>     c.getCookie();
>   }
>
>   public void getCookie () {
>     try {
>       URL url = new URL("http://www.server.com/");
>       URLConnection connection = url.openConnection();
>
>       InputStream in = connection.getInputStream();
>       cookie = connection.getHeaderField("Set-Cookie");
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
>
>     System.out.println(cookie);
>   }
>
>   public void sendCookie() {
>     try {
>       URL url = new URL("http://www.server.com");
>       URLConnection connection = url.openConnection();
>       connection.setUseCaches(true);
>       connection.setDoOutput(true);
>
>       connection.setDoInput(true);
>       connection.setRequestProperty("COOKIE", cookie);
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
> }

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to