How do you keep the same URL connection connected continuously?

I am trying to extract information from a web page, but it puts a cust_id in the middle of the URL. It generates the cust_id randomly everytime you use the site. I connect to the initial URL to find the cust_id, I substring that to the new URL and then make a new connection to extract the information, but the web page gives me an error saying that it doesn't recognise the cust_id. As if it was a new connection with the wrong cust_id.
How can I keep the first connection open and with the same cust_id information and then jump to another web page but using the initial connection. Using IE6 I can just cut and paste the second URL and get to the page, but with my java application it doesn?t work. Please have a look at my code and let me know if I am doing anything wrong.
URL inputURL;
     String inputLine;
     URLConnection connection;
     String page = "";
     int x;
     String cust_id1 = "";
     String cust_id2 = "";
     String site;
     File outputFile = new File("web.txt");
     FileWriter out = new FileWriter(outputFile);
   try
     inputURL = new URL("http://www-ets.woolworths.com.au/ets/owa/login?topage=search");
     connection = inputURL.openConnection();
     BufferedReader inputStream = new BufferedReader(new InputStreamReader(connection.getInputStream()));
     while ((inputLine = inputStream.readLine()) != null)
          page = page + inputLine;
          System.out.println(inputLine);
          x = inputLine.indexOf("cust_id=");
          if (x != -1)
          cust_id1 = inputLine.substring(x, x + 14);
          PrintWriter file = new PrintWriter(new FileOutputStream("web.txt"));
          out.write(page);
          out.close();
          System.out.println("1st time successful");
          System.out.println(cust_id1);
          //inputStream.close();
          //extracted the customer id, now able to search for the product
          //test for milk
     site = "http://www-ets.woolworths.com.au/ets/owa/items?search_pattern=milk&";
     site = site + cust_id1;
     site = site + "&imode=search&search_option=";
     System.out.println(site);     
     inputURL = new URL(site);
     BufferedReader inagain = new BufferedReader(new InputStreamReader(inputURL.openStream()));
     //tried the connection way
     //connection = inputURL.openConnection();          
     //BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
     while ((inputLine = inagain.readLine()) != null)
          //System.out.println(inputLine);          
          x = inputLine.indexOf("cust_id=");
          if (x != -1)
          cust_id2 = inputLine.substring(x, x + 14);
          System.out.println(cust_id1);
          System.out.println(cust_id2);
          System.out.println("2nd time completed");
          inputStream.close();
   catch(ArrayIndexOutOfBoundsException obe)
            System.out.println("Usage: FetchURL url");
   catch(IOException ioe)
            System.out.println("IO Exception");

Please have a quick look at my code and see if I am doing anything wrong. I havent been able to set the correct cookies and the output html page comes up with an error saying that it could not retrieve my request. This time there is no mention of invalid cust_id.
          try
               URL inputURL = new URL("http://www-ets.woolworths.com.au/ets/owa/login?topage=search");
               connection = inputURL.openConnection();
               System.out.println("filename = " + inputURL.getFile());
               BufferedReader inputStream = new BufferedReader(new InputStreamReader(connection.getInputStream()));
               while ((inputLine = inputStream.readLine()) != null)
                    //System.out.println(inputLine);
                    page = page + inputLine;     
                    x = inputLine.indexOf("cust_id=");
                    if (x != -1)
                         cust_id = inputLine.substring(x + 8, x + 14);
               out.write(page);
               out.close();
               System.out.println("extracted cust_id: " + cust_id);
               for (int i = 1; i <= 30; ++i)
                    System.out.println("    Header " + i + ":  " + connection.getHeaderFieldKey(i) + ": " + connection.getHeaderField(i));
                    header = header + connection.getHeaderFieldKey(i);
                    header = header + ": ";
                    header = header + connection.getHeaderField(i);
               outcookie.write(header);
               outcookie.close();           
               inputStream.close();          
               //extracted the customer id, now able to search for the product
               //test for milk
               String url2 = "http://www-ets.woolworths.com.au/ets/owa/items";
               //String url2 = "http://www-ets.woolworths.com.au/ets/owa/login?topage=search";
               inputURL = new URL(url2);     
               connection = inputURL.openConnection();     
               connection.setDoOutput(true);
               //connection.setUseCaches(false);
               System.out.println("filename = " + inputURL.getFile());
               String date = "; expires=Mon, 28 Jan 2002 02:53:17GMT; path/;";     
               String date1 = "expires=Sun, 31 Dec 1989 14:00:00 GMT; path/;";
               connection.setRequestProperty("cookie", "qwc=" + cust_id + date);
               connection.setRequestProperty("cookie", "cust_id=" + cust_id + "; path=/;");
               connection.setRequestProperty("cookie", "cd=2%40142%40%40%40%40N%40; path=/;");
               connection.setRequestProperty("cookie", "state=NSW; path=/;");
               connection.setRequestProperty("cookie", "dsd=1; path=/;");
               connection.setRequestProperty("cookie", "sb1=0%2A%2D645746%2D0%2A; path=/;");
               connection.setRequestProperty("cookie", "sb2=0; " + date1);
               connection.setRequestProperty("cookie", "sb3=0; " + date1);
               connection.setRequestProperty("cookie", "sb4=0; " + date1);
               connection.setRequestProperty("cookie", "sb5=0; " + date1);
               connection.setRequestProperty("cookie", "sb6=0; " + date1);
               connection.setRequestProperty("cookie", "sb7=0; " + date1);
               connection.setRequestProperty("cookie", "sb8=0; " + date1);
               connection.setRequestProperty("cookie", "sb9=0; " + date1);
               connection.setRequestProperty("cookie", "sb10=0; " + date1);
               connection.setRequestProperty("cookie", "sbn=; path=/");
               connection.setRequestProperty("cookie", "search=milk; " + date1);               
               //connection.setRequestProperty("Content-type", "application/octet-stram");
               //connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
               //String parms = "?search_pattern=" + URLEncoder.encode("milk") + "&cust_id=";
               //parms = parms + URLEncoder.encode(cust_id);
               //parms = parms + "&imode=" + URLEncoder.encode("search") + "&search_option=";
               //System.out.println("parms : " + parms);
               String parms = "?search_pattern=milk&cust_id=";
               parms = parms + cust_id;
               parms = parms + "&imode=search&search_option=";
               System.out.println("parms : " + parms);
               PrintWriter outStream = new PrintWriter(connection.getOutputStream());
               outStream.println("parms");
               outStream.close();               
               BufferedReader inputStream1 = new BufferedReader(new InputStreamReader(connection.getInputStream()));     
               //BufferedReader inagain = new BufferedReader(new InputStreamReader(connection.getInputStream()));
               while ((inputLine = inputStream1.readLine()) != null)
                    //System.out.println(inputLine);
                    page2 = page2 + inputLine;
                    x = inputLine.indexOf("cust_id=");
                    if (x != -1)
                         cust_id2 = inputLine.substring(x + 8, x + 14);
               out2.write(page2);
               out2.close();
               System.out.println("2nd attempt cust_id" + cust_id2);
               for (int i = 1; i <= 30; ++i)
                    System.out.println("    Header " + i + ":  " + connection.getHeaderFieldKey(i) + ": " + connection.getHeaderField(i));
                    header2 = header2 + connection.getHeaderFieldKey(i);
                    header2 = header2 + ": ";
                    header2 = header2 + connection.getHeaderField(i);
               outcookie2.write(header2);
               outcookie2.close();      
               inputStream.close();
          }The original web page to get the cookie is
http://www-ets.woolworths.com.au/ets/owa/login?topage=search
Enter a search product eg milk and that is the second page I am trying to extract.
You will notice in the middle of the url is cust_id.
Am I going about this 2 pages completely wrong?

Similar Messages

  • How to keep the same URL with a redesigned website

    I have completely redesigned my muse website and want to replace the old one which is already live. How do I go about doing so and keeping the same URL?

    Hi
    You can upload the site to root which would replace the existing one.
    http://helpx.adobe.com/muse/topics/exporting-publishing.html
    Thanks,
    Sanjit

  • How can you keep the highest iphone 4s Video quality the same when exporting it from iMovie.

    How can you keep the highest iphone 4s Video quality the same when exporting it from iMovie.

    InDesign's PDF export engine does not transcode your videos, they are embedded exactly as they were in the original file. The Flash Player runtime which displays video inside PDF files may not show a perfect match to Quicktime etc. because most video playback tools aren't designed for a color-calibrated workflow, but they should be close.
    The playback quality (blocking and aliasing) will be affected if the clip is not playing at 100% (screen pixels != video pixels) and in PDFs with the standard video player widget, that will only ever happen when you use 'floating window' mode. PDF pages have physical dimensions, so viewing them at "100%" does not make them match screen pixels.
    If you don't mind the video clip being smaller than the media annotation in which it's playing, then use my free upgrade to the Acrobat playback widget - VideoPlayerX - which maintains 1:1 pixel scale until the page is zoomed out too far for it to fit. You can install the widget into InDesign so it's used by default when exporting.

  • My macbook wont allow me to use the same hotmail address as i used on my other computers. How can I keep the same email and log into it on a macbook?

    my macbook wont allow me to use the same hotmail address as i used on my other computers. How can I keep the same email and log into it on a macbook?

    That indicates a hardware failure. Read here:
    http://support.apple.com/kb/ts1559
    If nothing works, you most likely have a hardware failure. Make an appointment at an Apple store to confirm.

  • I have had to semi-reset and reinstall my hp6500a plus. How do I keep the same eprint email address?

    I have had a network blowup and a new computer and was told to do a semi-reset and full install on my Inkjet hp6500a plus. How do I keep the same eprint email address which I have given out to a number of people? When I did the install I seem to have been re-assigned a new @hpprint address and can't find how to change it back.

    Hi,
    I affraid you will not be able to use the same address.
    Due to security reasons any removed ePrint address (due to Web Services removal, product reset or product replacement) is blocked for any user for 6 months period.
    You may select a difference customized address by following the steps below:
    http://h10025.www1.hp.com/ewfrf/wc/document?docname=c02940150&cc=us&dlc=en&lc=en
    Regards,
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • How do I keep the same file size, going from tiff to jpg?

    Going from tiff to jpg, how do I keep the same file size? Seems like I am not able to save the jpg´s in 16-bits... Thanks!

    file size? you mean dimensions or file bytes ?
    Jpg is compressed so it won't be the same
    Tiff is losless / lossy format to get the better quality
    as for 16bit jpg the format doesnt support it

  • HT3215 How do you keep the clock face showing all the time without the screen going dark?

    How do you keep the clock face showing all the time without the screen going dark?

    Thanks.  I saw a number of answers to the same basic question after I posted my question and apparently there are ways to to keep it on but, as you said, it will drain the battery quickly.

  • When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???

    When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???  All of the songs that were put on there from a CD will sync, but the songs that were purchased.. "cannot be found"   How can we merge them?? or how can we share all songs.. purchased or not!

    When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???  All of the songs that were put on there from a CD will sync, but the songs that were purchased.. "cannot be found"   How can we merge them?? or how can we share all songs.. purchased or not!

  • How can you use the same e-mail address for multiple ipads?

    I have two iPads.. an iPad and an ipad 2.  I registared my new ipad 2 and now my old ipad is will not let me log on and is telling me that my e-mail address is already in use.  how can you use the same e-mail address for multiple ipads?

    And by using the same Apple ID you can also share purchases.  If you have a different Apple ID for each iPhone then you can't share purchases.

  • HT4489 this is ridiculous! how do you keep the size of the picture for a contact that small? it is usually a piece of  a lager picture... any way to make the size of the pictures the 224 KB they want? I always thought the application cropped the picture t

    this is ridiculous! how do you keep the size of the picture for a contact in the address book that small? it is usually a piece of  a lager picture... any way to make the size of the pictures the 224 KB they want? I always thought the application cropped the picture to fit their requirements...
    Help
    Leo

    Gem
    Events are organised strictly on date and time, as read by iPhoto from the Exif data in the Photo. You cannot manually sort.
    Create Albums. You can do much more organising with Albums, use Photos from different events, place them as you will. Best of all, Albums use no disk space at all. They simply reference the file on the Hard Disk. So a pic can be 1, 10 or 100 Albums with no wasted disk space whatever.
    Regards
    TD

  • Hi, how can I keep the same zoom level for all the pages I view in Safari and even when I close and open it.  Indeed with a 27 inch Imac I have a lot of space, most of the websites are built for smaller resolutions  and my sight is dropping !   Thx

    Hi, how can I keep the same zoom level for all the pages I view in Safari and even when I close and open it.  Indeed with a 27 inch Imac I have a lot of space, most of the websites are built for smaller resolutions  and my sight is dropping !   Thx

    Hi, how can I keep the same zoom level for all the pages I view in Safari and even when I close and open it.  Indeed with a 27 inch Imac I have a lot of space, most of the websites are built for smaller resolutions  and my sight is dropping !   Thx

  • When burning a playlist to disc, how do you keep the songs in original order?

    When burning a playlist to disc, how do you keep the songs in original order?

    If you are burning an audio CD, they will burn in sequential order as in your playlist.
    If you are burning an MP3 CD or a data CD, they will burn as individual files, and can be sorted any way you like when you view the CD.  For an MP3 CD, the files will be prepended with a sequence number, so if you sort by filename, they will be in the original order.

  • How do you keep the browser heading from showing?

    How do you keep the browser heading from showing in the
    output? I did this once but can't figure out how!
    Thanks in advance,
    Rosie

    You asked...
    quote:
    Is there a way to shrink the application you're capturing so it
    fits within a given capture window rather than requiring scrolling,
    or would I have to go back to the application developers for that?
    (I realize that would shrink the size of everything on the screen,
    but in some cases, that would be worth it to be able to show a
    window without scrolling.
    If, by "shrink" ... you mean by using the AppSizer, the
    answer is "not really". You can configure AppSizer to a defined
    size, then with the mouse pointer double-arrowed on the "edge" of a
    window, right-click and your window-size selections will appear in
    the AppSizer "list" (that you set up) and can be selected there.
    But there is no re-scaling of the window contents, if that is
    what you mean, so the smaller window may now require scrolling.
    But keep in mind that if you use the recording option for
    "Software Simulation" > "Custom Size", you can then snap the
    application window to that size...

  • Lightroom 5 make adjustments want to transfer to photo shop to make additional adjustments. how do you keep the adjustments made in lr5 when photo is transferred to photo shop

    lightroom 5 make adjustments want to transfer to photo shop to make additional adjustments. how do you keep the adjustments made in lightroom 5 when photo is transferred to photo shop
    I am not able to keep the changes made in light room when I transfer to photo shop

    Something you need to understand. Unless you are using the latest version of Photoshop Elements, it's possible that some of the adjustments that you make in Lightroom won't transfer to Elements if you choose the option to open anyway. If you choose the option to edit a copy with Lightroom adjustments then Lightroom will create a TIF or PSD file (depending on your preferences), and that file will include all of the adjustments that you have made using Lightroom. Then you can finish your work in Photoshop Elements.
    The process of transferring an image from Lightroom to Photoshop or Photoshop Elements involves the Camera Raw plug-in. It has to be used to interpret the Lightroom adjustments and apply those adjustments to the image after it has been converted. Files open in Elements or Photoshop or no longer raw images because those programs are incapable of editing raw image data. I don't know if this will help you in this situation. Feel free to ask if you have more questions.

  • When playing songs in iTunes playlist, How do you keep the next song from jumping to next song? I am working on song list updating other tracks info and then the next song starts and I lose my spot in song list?

    When playing songs in iTunes playlist, How do you keep the next song from jumping to next song? I am working on song list updating other tracks info and then the next song starts and I lose my spot in song list?

    Max OSX 10.6.8, iTunes 11.1
    I had a similar problem: I wanted to synch my playlist to my iphone. I like to have my playlist sorted by genre. But under each genre, albums are not sorted by the track numbers. This is a problem, especially when I am listening to club mixes when the DJ smoothly transitions from 1 track sequentially to the next one. Under the properties of each audio file, the Track Numbers and Disc Numbers are already there.
    My perfect solution was to turn On Sorting - Sort Album under View>Show View Options. Then, select all the songs in that album (Shift click, Cmd click, etc) , and Edit multiple item information (Cmd I). You will see Info-Video-Sorting-Options buttons. Click on Sorting. Then, under Sort Album, Enter the name of the album. Then OK.
    You should now have the playlist sorted by Genre, then each album individually sorted by track numbers. On your playlist you should see, if you scroll right, the column added called "Sort Album".
    Hope this helps.

Maybe you are looking for

  • My iMac is shutting down on my while its asleep

    My computer: - First generation G5 iMac - 1.8ghz (I think) G5, 512 MB ram - Latest OS 10.4.X Hi, It seems that when my iMac is asleep it randomly powers off. One minute I notice the light happily throbbing and snoozing away and the next minute it is

  • Assigning an IT field value to a variable

    Hi experts, I have a below piece of code:   TYPES: BEGIN OF lty_hrt1222,           low TYPE om_attrval,          END OF lty_hrt1222. DATA: lt_hrt1222 TYPE STANDARD TABLE OF lty_hrt1222. DATA: lv_low          TYPE        om_attrval. I want to assign t

  • Itunes movies not playing..

    Suddenly certain movies, purchased from the iTunes store, don't play anymore.  When I double click on them, it goes to a black screen with no sound.  I've already tried reinstalling iTunes, but no luck.  Strangely, this only occurs with some of my mo

  • The FM "DD_DOMA_GET" not released for 'remote' calls.

    Hi, When I try to import RFCs from my CRM system in XI, I am getting the following exception: com.sap.aii.ibrep.sbeans.upload.RemoteUploadException: The function module "DD_DOMA_GET" not released for 'remote' calls. Solution please!! Regards, Mahesh.

  • Can you use Crystal Reports for Enterprise to connect to BOE4 over the web?

    Hello, When I use Crystal Reports for Enterprise in BI Launchpad when I am connected on the LAN network it works. If I connect via the internet, it doesn't. I wanted to know if Crystal Reports for Enterprise only works if you are connected to Busines