subha
Posts: 3
Nickname: neithilath
Registered: Oct, 2002
cookies and java
Posted: Nov 7, 2002 10:50 PM
Advertisement
Hi, I am having a java program which was written to contact the domino server ,get authentication and perform some operations on it.(eg.Execution of simple servlet programs).But i am unable to get the cookie from the server through my program. While getting the authentication through browser i am setting the cookie as depicited below and it works fine(servlet program is getting executed). ******************************************************************** ****************** function doCookieL(nom,valeur) { document.cookie=nom+"="+valeur+"; ; path=/"; return true; } and onload="javascript:setFormFocus();doCookieL('DomAuthSessId','');" > *************************************************************************** *********** java program :Cookie is returned as null,Is it because of the problem in code or names.nsf? import java.io.*; import java.net.*; public class authen { public static void main(String args[]) throws Exception { String cookie = ""; try { URL theurl = new URL("http://192.168.10.55:8001/names.nsf?login";); HttpURLConnection hurl = (HttpURLConnection)(theurl.openConnection()); hurl.setDoOutput(true); hurl.setDoInput(true); hurl.setRequestMethod("POST"); hurl.setUseCaches(false); hurl.setFollowRedirects(true); hurl.setRequestProperty("Accept","application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif,image/x-xbitmap, image/jpeg, image/pjpeg, */*"); hurl.setRequestProperty("Accept-Language","en-us"); hurl.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); hurl.setRequestProperty("Accept-Encoding","gzip, deflate"); hurl.setRequestProperty("User-Agent"," Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); hurl.setRequestProperty("Connection","Keep-Alive"); String idpassword = "username=sakthivel&password=12345"; hurl.connect(); OutputStream o= hurl.getOutputStream(); byte[] by= idpassword.getBytes(); o.write(by); o.flush(); o.close(); int ic=0; String key=""; while (ic<=10) { key = hurl.getHeaderFieldKey (ic); if(ic<=10) { String value = hurl.getHeaderField (ic++); System.out.println(key + " - " + value); } } hurl.disconnect(); // cookie = hurl.getHeaderField ("set-cookie"); // cookie = hurl.getHeaderField ("DomAuthSessId"); cookie = hurl.getHeaderField ("err-cookie"); cookie = hurl.getHeaderField("SSOAuthSessId"); System.out.println("cookie is - " + cookie);//Cookie is returned as null } catch(Exception exp) { exp.printStackTrace(); } /* try { HttpURLConnection urlconnection = null; URL serverURL = new URL("http://192.168.10.13/servlet/testing";); urlconnection= (HttpURLConnection)serverURL.openConnection(); urlconnection.setRequestMethod("POST"); urlconnection.setRequestProperty("cookie","B24FCB7AA8D383EB36A63A6762989D3A"); urlconnection.setDoOutput(true); urlconnection.setDoInput(true); urlconnection.setUseCaches(false); urlconnection.setDefaultUseCaches(false); urlconnection.setAllowUserInteraction(true); urlconnection.setFollowRedirects(true); urlconnection.setRequestProperty("Accept-Language","en-us"); urlconnection.setRequestProperty("Content-type","application/x-www-form-urlenco ded"); urlconnection.setRequestProperty("User-Agent"," Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); urlconnection.setRequestProperty("Connection", "Keep-Alive"); urlconnection.connect(); } catch (Exception e) { e.printStackTrace(); } */ } } **************************************************************************** ****************************************** but how to get it done through a java program.Is it required to set the same in a java program to get cookie and if so,How should I get it done. Thanks and Regards Subha