Cookie managment in java

I'm trying to make a little application that logs onto an account I have on a server. I finally figured out how to POST data to a HttpURLConnection last night, but the prblm is the page requires cookies to be enabled. Does anybody know how to accept cookies using the HttpURLConnection class? My knowledge of HTTP isn't that great and the RFC documentaion neglects to mention anything about cookies (i'm guess HTTP wasn't designed with cookies in mind).
Any help would be apreciated.

Hi,
You might be in luck. Here is a small example. You'll have to adapt it to your needs!
               URL url = new URL("http://www.somesite.com/yup.asp");
               HttpURLConnection connection = (HttpURLConnection)url.openConnection();
               connection.setRequestMethod("POST");
               connection.setInstanceFollowRedirects( true );
               connection.setDoOutput( true );
               connection.setDoInput( true );
               connection.setFollowRedirects( true );
               connection.setUseCaches( true );
               connection.setRequestProperty( "Content-Type","application/x-www-form-urlencoded" );
               connection.setRequestProperty( "Connection","close" );
               connection.setRequestProperty( "Keep-Alive","300" );
               PrintWriter out = new PrintWriter(
                                        connection.getOutputStream());
               //////transmit username and password
               out.println("username=user&pwd=password");
               out.close();
               BufferedReader in = new BufferedReader(
                              new InputStreamReader(
                              connection.getInputStream()));
               String cookie1 = connection.getHeaderField("set-cookie");
               firstcookie="";
               if(cookie1!=null)
               { int index = cookie1.indexOf(";");
                    if(index > 0)
                         firstcookie = cookie1.substring(0, index);
               }Then when you login to the site again all you do is something like this:
               url = new URL("http://www.somesite.com/yup.asp");
               connection = (HttpURLConnection)url.openConnection();
               connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded" );
               connection.setRequestProperty( "Connection","close" );
               connection.setRequestProperty( "Keep-Alive","300" );
               connection.setRequestProperty( "Referer","somesite" );
                       //Notice this!!!!
               connection.setRequestProperty("Cookie", firstcookie);
               connection.setRequestMethod("POST");
               connection.setInstanceFollowRedirects( true );
               connection.setDoOutput( true );
               connection.setDoInput( true );
               connection.setFollowRedirects( true );
               connection.setUseCaches( true );There you go! Like i said, you'll have to adapt it to your needs.
GCS584

Similar Messages

  • Cookie management in java

    Hi,
    I am trying to write a crawler in java and I have difficulties getting the content. The website is using javascript, php and session ids and seems to detect if the request came from a human or not. I figured out that I need to hold the state of the current session but I don't exactly know how to do that. Does anybody already wrote such a crawler ?
    I found an open source project called httpUnit, which seems promising, but the javascript support is not so good and I get errors when I try to simulate the behaviour of a normal user.
    Chris

    Try looking into http://curl.sourceforge.net/
    Feature list: http://curl.sourceforge.net/docs/features.html
    "Curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP. Curl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, kerberos, HTTP form based upload, proxies, cookies, user+password authentication, file transfer resume, http proxy tunneling and a busload of other useful tricks."
    I hope this helps.
    -Richard Burton

  • Fire fox has no cookies managment options in versions above 3.0

    How to get cookies management for firefox 3.6.2 under windows?
    How to uninstall Firefox 3.6.2 under windows?

    <u>'''Cookies options'''</u>
    Tools > Options > Privacy, "Firefox will:" must be set to "Use custom settings for history" for the cookie options to display. See: http://support.mozilla.com/en-US/kb/Options+window+-+Privacy+panel#Use_custom_settings_for_history
    ~~blue:On the system from which you posted the question:~~
    <u>'''''Other Issues''''': to correct security/stability issues</u>
    <u>'''Update Java'''</u>: your ver. 1.6.0.17; current ver. 1.6.0.20 (<u>important security update 04-15-2010</u>)
    (Firefox 3.6 and above requires Java 1.6.0.10 and above; see: http://support.mozilla.com/en-US/kb/Java-related+issues#Java_does_not_work_in_Firefox_3_6)
    ''(Windows users: Do the manual update; very easy.)''
    See: '''[http://support.mozilla.com/en-US/kb/Using+the+Java+plugin+with+Firefox#Updates Updating Java]'''
    Do the update with Firefox closed.
    <u>'''Install/Update Adobe Flash Player for Firefox'''</u>: your ver. 10.0 r42; current ver. 10.0 r45
    See: '''[http://support.mozilla.com/en-US/kb/Managing+the+Flash+plugin#Updating_Flash Updating Flash]'''
    -'''<u>use Firefox to download</u>''' and <u>'''SAVE to your hard drive'''</u> (save to Desktop for easy access)
    -exit Firefox (File > Exit)
    -check to see that Firefox is completely closed (''Ctrl+Alt+Del, choose Task Manager, click Processes tab, if "firefox.exe" is on the list, right-click "firefox.exe" and choose End process, close the Task Manager window'')
    -double-click on the Adobe Flash installer you just downloaded to install/update Adobe Flash
    -when the Flash installation is complete, start Firefox, and test the Flash installation here: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15507&sliceId=1
    *<u>'''NOTE: On Vista and Windows 7'''</u> you may need to run the plugin installer as Administrator by starting the installer via the right-click context menu if you do not get an UAC prompt to ask for permission to continue (i.e nothing seems to happen). See this: http://vistasupport.mvps.org/run_as_administrator.htm
    *'''<u>NOTE for IE:</u>''' Firefox and most other browsers use a Plugin. IE uses an ActiveX version of Flash. To install/update the IE ActiveX Adobe Flash Player, same instructions as above, except use IE to download the ActiveX Flash installer.
    *Also see: http://kb.mozillazine.org/Flash '''''~~red:and~~''''' [[How do I edit options to add Adobe to the list of allowed sites]]
    <u>'''Update Shockwave for Director'''</u>: your ver. 10.0; current ver. 11.5.7.609 (<u>important security update released 2010-05-11</u>; see http://www.adobe.com/support/security/bulletins/apsb10-12.html)
    NOTE: this is not the same as Shockwave Flash; this installs the Shockwave Player.
    SAVE the installer to your hard drive (Desktop is a good place so you can find it). When the download is complete, exit Firefox (File > Exit), locate and double-click in the installer you just downloaded, let the install complete.
    IMPORTANT: I have found it wise to always restart your system after doing anything with Adobe products.
    See: '''[http://support.mozilla.com/en-US/kb/Using+the+Shockwave+plugin+with+Firefox#_Installing_Shockwave Installing Shockwave]'''

  • Where is the cookie manager on Firefox. Can I set Firefox to ask me first to allow individual cookies?

    I read the follow article.
    http://www.mozilla.org/projects/security/pki/psm/help_21/using_priv_help.html
    In this article under "Managing Cookies Site-By-Site" It said
    "To control cookies on a site-by-site basis:
    1. Open the Tasks menu, choose Privacy & Security, and then choose Cookie Manager.
    2. Choose "Unblock Cookies from this Site" or "Block Cookies from this Site."
    When you are warned (while browsing) that a web site is requesting to set a cookie, you can click Yes to allow or No to deny the cookie. You can also select the option for your browser to "Remember this decision."....
    My questions is 1. I can't find the cookie Manager in firefox (I have the latest version). The article said "Open task menu, choose Privacy&Security... is that they same as under menu bar, tools, options, privacy (but under this option I don't see the cookie manager mention in the article. (I am thinking what they are describing is not for the version of firefox I have?).
    Bottom lines, I want to set Firefox so It will ask me each time the website want to install a cookie and for me to decide to allow that or not. I article above seem to describe how to do that but either I am looking in the wrong place or I am not doing it right.
    thanks in advance.
    panzer_ace

    Hi,
    I think that what you are searching be in Tools >> Options >> Privacy >> On Firefox will: change to "Use custom settings for history" then Button Show Cookies will be allowed and you will see the cookies in your browser in the next window
    If you uncheck "Accept cookies from sites", probably the sites that need cookies will alert you that you need active the storage cookies

  • Enterprise Manager 10g Java Console

    Hi ,
    I want to use EM 10g in order to set up the replication environment.
    In the Administration tab of the EM 10g there is a TIP at the bottom of the tab page ....
    TIP Use the Enterprise Manager 10g Java Console to manage Advanced Replication and Workspace.
    Which is the Enterprise Manager 10g Java Console and how can i call it.....??????
    NOTE: The database 10g v.2 is installed in Windows XP os.
    Thanks ,a lot
    Simon

    The EM 10g Java Console can be installed from the Oracle 10g Client CD and it is used the same way the 9i OEM. The difference is that EM 10g Java Console is only used in Stand-alone and does not include connection to a Management Server.
    It has limited functionality. There are a lot of features not available in it and is only available as a backup to some functionalities not yet in Grid Control and DB Control. (e.g, There is no Replication in 10.1 Grid Control, but it is in 10.1 Java Console). It will be phased out in future Releases (no idea which release yet).

  • Firefox 4 does NOT play well with Maxa Cookie Manager

    Even when I am logged out of Firefox 4 ...It shows that it is still running and WILLNOT allow me to delete cookies in firefox

    Hello,
    please update to MAXA Cookie Manager 5.0.0.23 using the update check button in the about screen and restart Firefox after the installation. This should solve the problem.

  • Where to find Enterprise Manager 10g Java Console software on OTN?

    Hi All, Please let me know where to find Enterprise Manager 10g Java Console software on OTN? Appreciate your help!
    Thanks!

    "The Java Console program is on the Oracle 10G Client software CD. When you are prompted to choose the type of installation, select the Administrator option and the Java Console will be installed with the rest of the software. After the installation is complete, navigate to the Oracle home's bin directory where you installed the Oracle Client and type in:
    oemapp console
    "

  • Memory management in Java

    HI all,
    I want to know what is memory management in JAVA means ?Is it related to memory management of java VM.?

    Sorry for posting in wrong area. also sorry for cross posting . i close this discussion as i have posted a new topic. so dont reply plz.

  • Bookmarks and Cookies Management got WORSE!

    In earlier FF versions, I was able to delete individual cookies easily from the list, why have they changed it so that now we can only delete ALL of them?
    The Bookmarking Window was resizeable in earlier versions, now we have this tiny box, not resizeable, gives bad oversight, and sometimes bookmarks into wrong categories (when you "doubleclick" by mistake.
    This really sucks, please bring back the old system!!!

    The bookmarks window for saving a new bookmark hasn't changed since Firefox 3 came out, like 2 years ago. Try the Add Bookmark Here ² extension - the "Page Bookmarked" window can be dragged to as large as you want it to be with the + (plus symbol) in the lower-left corner of that window:
    https://addons.mozilla.org/en-US/firefox/addon/3880
    A support thread for that extension is here:
    http://forums.mozillazine.org/viewtopic.php?t=522643
    As far as cookies management goes, the Options panel for Privacy was changed for Firefox 3.5 (a year ago), but the Show Cookies dialog box is the same as it was in Firefox 2 ''(and maybe even Firefox 1., but the oldest version I now have installed is 2.0.0.20 - so I can't say for certain)''.
    If you are not happy with the interface for removing specific cookies, look at the various cookie related extensions for one that is easier for you to use.
    [https://addons.mozilla.org/en-US/firefox/search/?q=cookies&cat=all&lver=any&pid=1&sort=&pp=20&lup=&advanced= AMO search for "cookies"]

  • Memory Management in Java With Garbage Collector

    i have so many doubts With Management in Java.
    Please send me the Link
                 Thanqqqqqqq
                         Guru

    Hi Guru,
    The following link might be helpful to you:
    http://java.sun.com/docs/hotspot/gc/
    Regards,
    Anuradha.B

  • My safari screen is greyed out, I checked and found a response to this question.  I went to settings and cleared history, cookies, and cache, java script is on and I restarted, screen is still grey, cant touch it to do a thing.  Help!

    my safari screen is greyed out, I checked and found a response to this question.  I went to settings and cleared history, cookies, and cache, java script is on and I restarted, screen is still grey, cant touch it to do a thing.  Help!

    That is usually the fix but try this now.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple logo appears - ignore the red slider - let go of the buttons. See if that helps.
    You can also try this - quit Safari. From the home screen - Double tap the home button and your recent apps appear the bottom. Tap and hold down on the Safari icon until it wiggles. Tap the minus sign in the upper left corner to close the app. Tap the home button twice. Restart the iPad.
    Message was edited by: Demo

  • Cookie manager for opera mac?

    Hello: is there a cookie manager for Opera 9.1 mac? The built-in one does not measure up to mozilla's cookie managers. Thanks.

    Hey look at this:
    http://supportforums.blackberry.com/rim/board/message?board.id=blackberryformac&thread.id=2499&jump=...
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Cookie management in Safaari

    Hello All
    New user, just Switched. I don't find a menu option for cookie management in Safari. As is the case with Firefox or IE, I am expecting a menu feature which would allow me the option of "approving" some sites to leave cookies, protecting these cookie from deletion when deleting the general group of cookies. Is it there and I'm not looking in the right place?
    Thanks for your help
    Warren

    Disregard my post about Bookdog - that improves Safari's Bookmark management - another area Safari is weak in (I hadn't had my morning coffee yet).
    There are a few cookie managers on VersionTracker. At one time or another I had looked at each one but was not impressed enough to keep any of them.

  • Cookie Manager - use it to save/restore a particular cookie.

    Cookie Manager - http://cookiemanager.blogspot.com/
    Sometimes I login to a site & it seems to forget that I've been there & the info that I've input previously. That's particularily irritating if it's a game that I've taken to a high level.
    If there is doc to support it, I can't find the answer to my problem.
    The "Save" icon at the bottom-right doesn't appear to do anything, & I don't really want to save every cookie anyway.
    The "Export" icon at the bottom appears to save all the cookies in a single file, which means that I'd be restoring all my out of date cookies?
    What I want to do is to save one, or a few cookies & then be able to add/attach them to cookies already on the computer. Is this possible?

    Check out the cookie manager add on [https://addons.mozilla.org/en-US/firefox/addon/cookies-manager-plus/ Cookies Manager Plus] or a few others you can search for on that same site.
    In Preferences/Options > Privacy > History > Show Cookies..
    you can manage them manually as well.
    Hope this helps!

  • I installed FF 4 and now the excellent Maxa Cookie Manager software won't work. Can I install and older version of FF over FF4? I could just uninstall 4.0 and re-install 3.* but I don't want to loose all my bookmarks.

    Maxa Cookie Manager software no longer records cookies since I installed FF4. So what will happen if I install FF 3.* over FF4?

    Glad to hear your prolbems have been sorted.
    Have had similar problems since performing a sofware update last week.
    Itunes has crashed.
    Can't be reinstalled.
    The software update won't work, neither will disk utility.
    Removing the .dmg files hasnt helped.
    Any suggestions?

Maybe you are looking for

  • Robohelp HTML V7 -Printed Documentation Why do I get 2 TOCs?

    Hi, I'm new to Robohelp using HTML V7 but will be upgrading to V8 shortly.  I've created Help Files, but additionally I need to create Word and PDF files from the same source.  I am getting two Table of Contents in my Word output...one numbered with

  • Cisco ISE and NDES?

    Wanting to use Cisco ICE in front of Windows Server 2012 or R2 NDES.  The following article states that NDES should NOT be clustered or load balanced and setting a single password is not supported. https://social.technet.microsoft.com/wiki/contents/a

  • Parameter in IT Resource for SAP Employee Reconciliation Connector

    Hello Everyone, I'm trying to make the SAP ER connector work for the first time, so i'm having some begginer problems. I need to put the right parameters in the SAP ER IT Resource, but I don't know what to put in the specific parameter called "Reposi

  • Social media link in itunes

    Hi Apple I love your products but why when I hear a great track on my iphone in my library I cant just click to share that to my social media You could even have a link to the store so if my followers liked it they could buy it All the "radio" apps l

  • What is the best product to clean an imac screen

    does anybody know what is the best product to clean an imac screen?