/*****************************************************************/ /* Copyright 2013 Code Strategies */ /* This code may be freely used and distributed in any project. */ /* However, please do not remove this credit if you publish this */ /* code in paper or electronic form, such as on a web site. */ /*****************************************************************/ package test; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class CookieTestClient { public static void main(String[] args) { try { URL url = new URL("http://localhost:8080/cookie-test/test"); URLConnection conn = url.openConnection(); conn.setRequestProperty("Cookie", "testCookie1=hello_there;testCookie2=goodbye_there"); conn.connect(); InputStream is = conn.getInputStream(); StringBuffer sb = new StringBuffer(); InputStreamReader isr = new InputStreamReader(is); int numCharsRead; char[] charArray = new char[1024]; while ((numCharsRead = isr.read(charArray)) > 0) { sb.append(charArray, 0, numCharsRead); } System.out.println("CLIENT RECEIVED: " + sb.toString()); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }