in reply to How to authenticate and upload file to a secured server

"Basic Authentication" has no relation to "BASIC" or even "Visual Basic".

The website doesn't use Basic Authentication. It (presumably) uses HTML forms and a session cookie.

Your proxy uses Basic Authentication, and that appears to work fine.

You never attempt to login (i.e. you never submit the populated login form).
I was confused by the useless my $request  = new HTTP::Request ("GET" => $login_url );
You do do a POST, but you don't provide any of the form fields. See the examples in HTTP::Request::Common.

Once you login, the session id will most likely be returned in a cookie. Your cookie jar code already handles that. Just use the same $ua for future requests requiring the session cookie.

Replies are listed 'Best First'.
Re^2: How to authenticate and upload file to a secured server
by KarthikK (Sexton) on Oct 18, 2007 at 17:35 UTC
    Hi thanks for the reply.
    1. The website uses BasicAuthentication and not a form based authentication.
    2. By Basic authentication i meant the login box that comes in IE or other browsers where we provide user name/password/domain
    3.I have to first login using the login.do page with the POST action. Since I don't have any form variables in that page i am not posting any username/pwd
    4. I even wrote the cookie to a file but the file does not contain any data. it is empty
    i am not able to install WWW::Mechanize Module using nmake. I copy pasted the PM file and other related modules to C:\perl\lib\WWW\Mechanize folder and Mechanize.pm to WWW folder.
    also i use Windows OS and not linux.

    Thanks and regards
    Karthik

      If it uses Basic Authentication, you'll need to call $ua->credentials, or create and use a subclass of LWP::UserAgent that overrides get_basic_credentials.

      By definition, if Basic Authentication was used, you'd get a 401 response including a "WWW-Authenticate: Basic realm="..."" header. Your site either doesn't use Basic Authentication, or you're not accessing the right page.

      Basic Authentication doesn't have any domain component. Just realm, user and password. Realm is set by the server and is not editable. I've seen the dialog to which you refer in the past, and it's not Basic Authentication. I don't know what it is.

      Look at the headers in your trace. You never got any cookie. That's why the file is empty. Basic Authentication doesn't use cookies anyway.

        Hi, thanks for your response. I tried with the $ua->credentials(). I got the following result

        1. I tried the https website, i always get status code 200 OK
        2. I tried with http://www.google.com, i get 407 Proxy Authentication Required
        3. I tried with a local intranet website, code works fine

        Also in the cookeis file i always get this only #LWP-Cookies-1.0
        any help would be really appreciated. i am struggling with this for last 2 weeks :-(

        Thanks
        Karthik