Catching 302 - temporarily moved code.

Hi,
I am trying to connect to a webserver and authenticate from a java program. Once authenticated, the server seems to send a cookie with the id and a "302 - temporarily moved" status.
I want to catch this part and save the cookie so i can issue more requests to the server. But when i use a URLConnection and read the stream data, I seem to get the final redirected page where the cookie is lost. Could someone please point me to what is wrong in the code below
public void login(String url,String userid,String pw)
//           Construct data
        String data = URLEncoder.encode("j_username", "UTF-8") + "=" + URLEncoder.encode(userid, "UTF-8");
        data += "&" + URLEncoder.encode("j_password", "UTF-8") + "=" + URLEncoder.encode(pw, "UTF-8");
        // Send data
        URL url = new URL(url);
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();       
       System.out.println(conn.getHeaderField("Set-Cookie"));   
        // Get the response
        BufferedReader bf = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = bf.readLine()) != null) {
            System.out.println(line);
        wr.close();
        bf.close();
}Edited by: suppandi on Oct 31, 2007 3:45 PM
Edited by: suppandi on Oct 31, 2007 3:46 PM

Do you know about Java API documentation? Very useful...
Look into and read about HttpURLConnection.setInstanceFollowRedirects() method.
http://java.sun.com/javase/6/docs/api/

Similar Messages

  • Web service 302 object moved error

    Hi All,
    Last week, IT changed the configuration on our Cisco content
    switch to redirect every page request to https. Everything seems to
    be working properly except for our Web services, which I can't seem
    to consume at all. Here's the error we keep getting:
    Could not perform web service invocation "myFunction"
    because AxisFault faultCode: {
    http://xml.apache.org/axis/}HTTP
    faultSubcode: faultString: (302)Object moved faultActor: faultNode:
    faultDetail: {}string: return code: 302
    Does anyone have any experience serving Web services over a
    content switch that forces a redirect over https? I even get this
    message when trying to consume over https. Our Web servers think
    they're not secured at all, maybe this is the problem? I just
    haven't worked with Web services very much.
    Thanks in advance!
    Cheers,
    -m

    ColdFusion sometimes has some problems connecting to
    webservices using HTTPS.
    Try Daverms's suggestion first. Recreating or refreshing the
    webservice in the CFADMIN might fix your problem. Otherwise, if
    that doesn't work I suggest:
    Try saving the WSDL to a local location and running the
    webservice off the local WSDL. The WSDL should have the location of
    the actual webservice in it (I think the tag is <ServicePort>
    or something like that), so it doesn't really matter where the WSDL
    resides.

  • Hi. I have temporarily moved away from home. I am using a different internet connection, and I have lost my bookmarks. How do I get them back?

    Hi. I have temporarily moved away from home. I am using a different internet connection, and I have lost my bookmarks. How do I get them back?

    Generally speaking, your bookmarks are private to your computer, and if you set up multiple Firefox profiles on your computer, to the one profile.
    Your bookmarks might be available to you at another location if you used the Sync service. In order to connect a new computer to the Sync service when you aren't near your old computer, you need a recovery key. https://support.mozilla.org/en-US/kb/share-bookmarks-tabs-and-more-your-other-computers#w_what-if-im-not-near-my-first-computer
    If you didn't use Sync or can't access your account, someone with access to your old computer could email you your bookmarks. Since there is a range of different ways to do that and the best choice might depend on what you can expect the person you ask to be able to do... could they start up Firefox in your profile and follow menu steps to export a file? Could they drill down into a hidden folder on the system, zip a file, and mail that to you? Etc.

  • Moving code from TFS 2012 to TFS 2013

    Hello - I am working on moving the existing code from TFS 2012 to TFS2013.
    Under Team Project Selections, there is new branch created as shown in figure.
    I am new to TFS, can anyone please provide me step by step procedure in moving code to this new TFS branch please ?
    MBH

    Hi MBH, 
    Thanks for your reply.
    The ProjectABC is a team project, and you created 3 branches in this ProjectABC team project? If yes, this ProjectABC created in which collection and in which TFS Server?
    Project.Global is a new branch? Project.Global is not a new team project? 
    Project.Global created in which collection and in which TFS Server?
    I’m confuse with your team project and branch concepts. For the TFS collection, team project and branches, please refer to below documents:
    Team Project Collection:
    https://msdn.microsoft.com/en-us/library/dd236915.aspx
    Team Project:  https://msdn.microsoft.com/en-us/library/ms181477.aspx
    Branches:  https://msdn.microsoft.com/en-us/library/ms181425.aspx
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • "Your mailbox has been temporarily moved on Microsoft Exchange Server"

    Exchange 2003, Outlook 2007
    In Outlook, the Inbox folder does not show up under Mailbox - User Name. Starting with "Outlook Today" and clicking on the "inbox" like he can get to his messages.
    In OWA the envelope icon shows up but instead of saying "Inbox" it had a URL like "http://video.google.com&search="...
    I used exmerge to extract the data for the user, deleted the mailbox, then used exmerge to import it back.
    "Inbox" now shows up in OWA but when Outlook is launched it gives this message:
    "Your mailbox has been temporarily moved on Microsoft Exchange Server. A temporary mailbox exists, but might not have all of your data. You can connect to the temporary mailbox or work offline with all of your old data. If you choose to work with your old data, you cannot send or receive e-mail messages."
    Did I miss a step somewhere?

    I just encountered the same problem, and was able to get all of my old data back to my new profile (contacts, saved e-mails, inbox folders, etc.).  Before creating a new profile, when the error message appears,
    choose the option to use old data.  When outlook loads (using Outlook 2010), go to File -> Options and click on 'Advanced'.  You should see an 'Export' section, click on the 'Export' button.  An 'Import and Export Wizard'
    window will appear, click on 'Export to a File' and click next, then choose 'Outlook data file (.pst)'.  The next screen will ask you a folder to export, in which you can choose from all your outlook folders...for a complete backup, I suggest choosing
    the root folder.  It should be the name of your profile, for example: "username @hotmail.com".  Make sure 'Include subfolders' is checked.  The final screen will ask what location to store the .pst file in, and if you want to add a password
    to it.  Now you've backed up all your Outlook data :)
    To import the .PST to your new profile, make sure to change Outlooks default profile to the new one you've created (as Deli suggested).  When outlook loads up, click on File -> Open, and then click on 'Import'.  Choose 'Import from another program
    or file' and click next, then choose 'Outlook data file (.pst)' and click next.  Now you just point it to the .pst file you exported earlier, and all of your information will be imported into Outlook in its own folder.  From there you can drag everything
    (emails, contacts, etc.) into the folders that you want.  And that's it, hope this helps someone else.

  • Catching the succeed BP code

    Dear Expert!
         i would like to ask how to catch the BP code that return after adding transaction successfully in UI API (VB.net or C#).
    Thanks in advance.

    Hi Dara,
    If I am getting your question properly then you want to get the BP Code after adding it to Business Partner Master Data ?
    If it is so you can use the form data event. After the form data is added you can use a query as follows:
    Select MAX(DocEntry) from OCRD
    Or
    Select top 1 DocEntry, CardCode   from OCRD order by DocEntry desc
    This will give you the BP Code that is added very last.
    Hope it helps.
    Thanks & Regards
    Ankit Chauhan

  • Compilation error, When moving code from 32-bit to 64-bit

    Hello,
    This Code compile on 32 bit system, but Getting Compilation error fro 64 bit,
    :/export/home/pshirode/rel_v95/cc_lib > make
    Making dependencies...
    cc -g -D__EXTENSIONS__ -D_SVID_GETTOD -I../h -I/app/oracle/product/9.2_32/precomp/public -I. `getconf LFS_CFLAGS | head -1` -D UT_TRACE_FUNCTION -I. -m64 -xarch=sparcvis -library=iostream,no%Cstd -H -w -E 2>&1 >/dev/null Bitmap.cc BitmapData.cc BitmapInputTxnStream.cc BitmapOutputStream.cc UnexpectedException.cc FieldData.cc FieldDataCollection.cc FieldDefinition.cc FieldDefinitionCollection.cc OutputFixedStream.cc ParsingEngine.cc Schema.cc Statistics.cc String.cc TraceStream.cc TxnStream.cc c_api.cc SocketImpl.cc Socket.cc ServerSocket.cc UnixSocket.cc Thread.cc test.cc | grep -v License | grep -v command | ../dvl.bin/mkdep >.depends
    Dependencies updated...
    CC -g -D__EXTENSIONS__ -D_SVID_GETTOD -I../h -I/app/oracle/product/9.2_32/precomp/public -I. `getconf LFS_CFLAGS | head -1` -D UT_TRACE_FUNCTION -I. -m64 -xarch=sparcvis -library=iostream,no%Cstd -c Bitmap.cc
    "RuntimeException.h", line 131: Error: Function RuntimeException::~RuntimeException() can throw only the exceptions thrown by the function std::exception::~exception() it overrides.
    "RuntimeException.h", line 97: Error: Could not find std::exception::exception(const char*) to initialize base class.
    "RuntimeException.h", line 121: Error: xmsg is not a member of std::exception.
    "Bitmap.cc", line 62: Error: Cannot return int(Bitmap::*)()const from a function that should return int.
    4 Error(s) detected.
    make: *** [Bitmap.o] Error 4
    CFLAGS in Makefile
    # The system include directory must be specifically included first because some of the
    # ghost includes use system include file names (e.g., generic.h)
    # Modified these section to compile on TVLAPP1HAG
    CFLAGS += -D $(STDOUT_TRACE)
    #CFLAGS += -g -D$(MAINLINE) $(OUR_COLLECTION)
    #CFLAGS += -compat -Qoption ccfe -abirel=4.1
    #CFLAGS += -Qoption ccfe -abirel=4.1
    CFLAGS += -I. -m64 -xarch=sparcvis -library=iostream,no%Cstd
    #CFLAGS += -I. -mt
    # Add the flag for multi-threaded apps
    LDFLAGS += -lsocket -lnsl -lthread
    # declare an empty macro for compiler directive flags, to be command-line
    # driven (ie, for -D directives)
    CCFLAGS=
    CCFLAGS += -DRW_NO_CPP_RECURSION
    # The following manipulation of CC and overriding the .cc.o suffix
    # dependency is removed here to use what is supplied by default int
    # the h/common.mak file.
    #XX = CC
    #CC = CC
    #COMPILE = $(CC) -o $*.o $(CFLAGS) $(CCFLAGS) -c $*.cc
    #.cc.o:
    # $(COMPILE)
    #.DEFAULT:
    # $(COMPILE)
    #all: $(TEST_OBJS) $(PGM_EXEC)
    all: $(TEST_OBJS)
    #install:
    # $(INSTALL) $(PGM_EXEC)
    $(TEMPLATE_CONTAINER).o: $(TEMPLATE_CONTAINER).cc
    $(CC) -o $*.o $(CFLAGS) -pta -c $*.cc
    # Uncomment the following lines, and uncomment the appropriate MAINLINE
    # setting to create your desired test program for a cc_lib routine. Normally
    # we simply want to create the cc_lib .o files so this is commented out.
    #test exec
    $(PGM_EXEC): $(INCLUDES) $(TEST_OBJS)
    @echo Linking test...
    $(CC) -g -o $(PGM_EXEC) $(TEST_OBJS) $(LDFLAGS) $(ROOT)/util/libutil.a
    checksum:
    /export/home/pshirode/rel_v95/cc_lib > CC -V
    CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25
    Please help ASAP

    This looks like exactly the same question you asked in the thread
    [http://forums.sun.com/thread.jspa?threadID=5335510]
    Please do not ask the same question in more than one thread.

  • Temporarily Moving Address

    Hi all,
    Really looking for some help & advice on my options.
    I've got to move out of my propeerty for some major construction works to be done, I'll be out for 8-10 weeks, I'm disabled and heavily dependant on internet for things like grocery shopping, banking, paying bills, email etc... so am wondering if there is any way I can tempoararily have my exisiting BT phone number, broadband service transferred from the property I'll be moving out of to the  temporary accommodation for the duaration of the renovation works, then transfer them back again when works have been completed and I return.  Or would I be  better off just depending on my mobile phone for phone calls and using a friends broadband connection to make use of internet services to avoid any disruption or mix ups with the transferring back and fore of the BT line details...!!
    If there's anyone who has any exxperience of a similar situation and what they did, or how they found BT's customer service under such circumstances, I'd love to hear from you...!!
    Thanks in advance

    Welcome! I'm not sure whether a temporary change is theoretically feasible or not. What is clear from this forum though is that such service changes are often subject to considerable delay and don't always go smoothly. If I was you I would probably leave well enough alone and go for the workround, especially as you would be dependent on two moves in a relatively short period.
    The words booze-up and brewery spring to mind. 
    [EDIT: Needed a cuppa in the middle of writing this so didn't see KB's advice that it's not on anyway.]
    You can click the white star next to this message if you think it was helpful.

  • Moving code from class to stage

    I have this code in a class that retrieves todays date. How
    can I show the date in a textfield?
    Or can I modify the code and just put it in my scene so I
    won't have to call the class?

    You can put this on the timeline:
    var someBirthday:Date = new Date();
    trace(someBirthday.getDate());

  • Moving code view window

    I've just started using DW 2014.1 In split view my code window appears to the right. How do I change this so that Live View is to the right of code view instead? Thanks.

    Try a different Workspace - Coder or Designer.
    Use View > Split Vertical
    You can also create a custom workspace.
    Nancy O.

  • Temporarily moving RDSH Host from Farm

    Hi,
    I have four 2008 r2 rdsh hosts in a load balancing remote dektop farm.  I need to install software on each of the servers and don't want users to be able to log in from the network while I am doing this(although I would still like to be able to log
    in as users profiles to the RDSH server).  Is there a way for me to temporarily remove an rdsh server from farm so I can do this?

    That approach probably won't work.
    You'll want to backup the original site, change the URL so it's free for re-use, then restore the site collection into the new Web Application with the relevant URL. Most of those steps are described here:
    http://blogs.technet.com/b/heyscriptingguy/archive/2013/12/19/migrating-host-named-site-collections.aspx

  • Has anyone ever moved code into Inkling from InDesign?

    I have used the Inkling Habitat plugin and gotten code into Habitat, but the tags don't seem to be correct.  I was wanting to know if anyone else has done this?
    I uploaded existing PDF's into INDesign using Recosoft's PDF2ID converter.

    That is phishing attack
    Someone, other then Apple, sent it to you
    Read http://support.apple.com/kb/ht4933
    Allan

  • Various Site Problems

    http://jobs.oracle.com/
    Code is as follows:
    <!-- Copyright &copy 1995,1998, Oracle Corporation, All Rights Reserved. -->
    <HTML>
    <BODY>
    <title>HTML META tag refresh</title>
    <meta http-equiv="Refresh" content="0;url=http:/jol_ext-jolap-dad/plsql/jol_www_pages_pkg.jol_intro">
    </head>
    </html>
    Seven lines of code total, containing four problems ... not a great impression.
    1. Comment contains &copy ... html character codes aren't necessary in a comment, and even if they were, it's missing the terminating semicolon to make it valid.
    2. First tag after <html> is <body>, when it should be <head>
    3. The content of the meta refresh lists the URL as http:/jol_... I'm not sure where to start with this one. It should either be a relative URL (i.e. url=/jol_ext-...) or an absolute URL (i.e. http://jobs.oracle.com/jol_ext-...). This is some horrible attempt to do both, and ends up doing neither.
    4. The second to last tag is </head>. While this is half correct, since the meta tag should precede the closing </head> tag, there is no corresponding opening <head> tag, so the tags are mismatched. According to the order in which tags were opened, this "should" be </body> (which would also be wrong, for a different reason.
    [5. This isn't really an error, but a nitpick. An http response code 301 should probably be used in this situation instead of a crappy <meta> refresh. Or, even better, just put the actual content in the web site root directory ... no redirect needed. If you do insist on using a meta redirect, the title of the page should probably be something more display-friendly, such as "Redirecting, please wait," instead of a low-level implementation-specific note.]
    Then, when I went to report this problem, naturally I go to www.oracle.com -> Contact us, to find a "site feedback" link. As others have pointed out before [ http://forums.oracle.com/forums/thread.jspa?messageID=1735536 ], no such link exists. However, in visiting the "Contact Us" page, an HTTP authentication message appears for login.oracle.com. I tracked this down to the "image" /corporate/contact/dotted_horizontal.gif ... which actually results in an HTTP 302 temporarily moved message, redirecting the browser to https://login.oracle.com/pls/orasso/orasso.wwsso_app_admin.ls_login?site2pstoretoken=v1.2~5426~A2B7981364[...]
    This is further complicated by the fact that [apparently] this page prompts Opera for http authentication, and loads a regular web page for Firefox and Internet Explorer. Regardless, it's at least slightly broken (probably in at least two ways).
    For being "the information company," Oracle really needs to work on how their information is presented.

    Thanks. I googled for oracle site feedback, and this was the closest I could find.
    I was a little curious, so I investigated further on the http authentication point.
    I simulated the HTTPS session, and discovered that, in fact, the server did respond differently based on the User-Agent string (ugh, browser discrimination ... one of my big pet peeves). When I used the User-Agent string from Internet Explorer 6 (Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)), the server responded with a 302 Moved Temporarily page. However, when I used the Opera User-Agent string (or a made-up string) (Opera/9.20 (Windows NT 5.1; U; en)), the server responded with a 401 Unauthorized HTTP response (and WWW-Authenticate: BASIC realm="Single Sign-On").

  • Apex in iframe broken in 4.1?

    Hi,
    I am experiencing a strange problem after I upgraded Application Express to 4.1.
    Every new application I create, will not work in an iframe. The frame shows up as empty (with chrome's element inspector showing the content as simply <html><head></head><body></body></html>
    But older applications (created in 4.0 and earlier) they show up fine without problems.
    I have tried all the themes in 4.1 they all do not work in an iframe and if I create new pages in an older application the new pages work fine in an iframe.
    So there is some change in the 4.1 that seems to be breaking apex apps within iframes.
    I looked at the sequence of events in the Chrome Network tab of the Developer Tools. I see a request for "f" with a response of "302" (temporarily moved), which is fine, its the session mechanism redirecting.
    Then I see another request for "f" which gets the response of "Canceled".
    I can get an apex error message to show by pointing to a non-existing page in a new 4.1 app, but that is the only response I have been able to get..
    Any ideas anyone?
    Oli

    That's interesting, tried the Sample Application with the following HTML file
    <html>
    <body>
    <h1>iFrame public page</h1>
    <iframe src="http://apex.oracle.com/pls/apex/f?p=29393:99:0" width="100%" height="300">
      your browser doesn't support iframes
    </iframe>
    <h1>iFrame protected page</h1>
    <iframe src="http://apex.oracle.com/pls/apex/f?p=29393:1:" width="100%" height="300">
      your browser doesn't support iframes
    </iframe>
    </body>
    </html>The first iframe works fine which loads a public page with using session zero.
    The second iframe which tries to include page 1 which is an authenticated page fails in IE8.
    I assume it must have something to do with redirects which are not correctly working in the iframe. It has definitely nothing to do with the new security settings to prevent click hijacking, because that's not enabled for that application.
    Will continue investigation.
    Regards
    Patrick
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • Anonymous user emails in CSC

    Does anybody ever sent guest emails through CSC? Looks like OOTB implementation needs to have a authenticated user for sending emails. I tried sending emails to anonymous user , but server is redirecting the request to other page thant he template URL specified. I am getting 302 (Temporarily moved), since my template URL is specified under the DCS-CSR context, which needs an authenticated profile to access the resources under that. Does anyone know in which servelt in the daf pipeline the context path is configured. The component which has the context in CSC is CSRConfigurator, but just wondering in which servlet it is been implemented. Any help or pointers would be appreciated
    Regards
    Rajesh Akavaram

    Thanks pramod7
    Yes, I am using the public site. But unless I'm missing something, Custom Lists (and associated forms) cannot be exposed to anonymous users. They are just not in the permissions list.
    I can create a page in the public site and add a Form Templates web part. The options I then get for creating a new form in the Form Templates library are Word Document, Excel Workbook, Powerpoint Presentation, One Note Notebook or Excel Survey. An
    InfoPath form is not an option. None of these (as far as I can see) allow for any data entered in the 'form' by a user to be stored in a Custom List for further processing. Most require the user to have Word/Excel/whatever on their machine, rather than
    just use the browser. The nearest you get is the Excel Survey, which at least regularises the data entered by an anonymous user into columns in a spreadsheet, but this is not sophisticated enough for, say, an online ordering system in which you would not want
    customers seeing each other's orders.

Maybe you are looking for