CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    Apr 2007
    Posts
    87

    Re: Attempting to log into website from java

    up

  2. #17
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Attempting to log into website from java

    Not much I can recommend. Your code is trying to mimic a browser's actions. Do it in the browser, watch what happens and try to do the same in your code.
    Norm

  3. #18
    Join Date
    Apr 2007
    Posts
    87

    Re: Attempting to log into website from java

    Yeah, that's what I've been doing. I've been comparing everything, but they look almost identical to me now :S

    How do sessions work in general? So when I log in, the website will send me back a session as a cookie? And from then on, all I would need to do is send that cookie as a part of the header when making GET requests? Or is there something more to it?

  4. #19
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Attempting to log into website from java

    That's all I know about it. Return the cookie the server gives you.
    Norm

  5. #20
    Join Date
    Apr 2007
    Posts
    425

    Re: Attempting to log into website from java

    In general you should be passing the headers untouched back to you as they may have added things in there (such as your session id). As long as it's passed the next time, you should still be able to maintain authentication and shouldn't be receiving a 403.
    ------
    If you are satisfied with the responses, add to the user's rep!

  6. #21
    Join Date
    Apr 2007
    Posts
    425

    Re: Attempting to log into website from java

    Also, double check that the implementation of your http connection can handle passing cookies back. I got burned by this once when I was running unit/integration testing against a project of mine where I need to startup an embedded application server and verify that I can hit some rest methods, which must pass authentication first.

    Using the jersey-apache-client did the trick (jersey-client.jar http connection does not do session management for you).

    The way I had to use my implementations was something like this:

    Code:
    // ...
    import com.sun.jersey.client.apache.ApacheHttpClient;
    import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
    import com.sun.jersey.api.client.WebResource;
    import com.sun.jersey.api.representation.Form;
    import javax.ws.rs.core.MediaType;
    
    public abstract class BaseTest {
        protected DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig();
        protected ApacheHttpClient client;
    
        // in some method
        public void init() {
           config.getProperties().put(DefaultApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES, true);
    
            client = ApacheHttpClient.create(config);
            resource = client.resource("http://my.server.com/auth");
            
            Form form = new Form();
    
            // construct my form object and post ... in my case with this media type.
            String result = resource.accept(MediaType.APPLICATION_JSON).post(String.class, form);
        }
    }
    ------
    If you are satisfied with the responses, add to the user's rep!

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured