hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <ROLWE...@de.ibm.com>
Subject Re: urgent: Problem using basic authentication
Date Mon, 26 Sep 2005 11:37:18 GMT
Hi,

when creating the AuthScope, pass the host instead of a URL.
That's "localhost", not "http://localhost". My first idea was to
pass "'MyRealm'" instead of "MyRealm" :-)

hope that helps,
  Roland





"Ramit Bhardwaj" <ramitb@cybage.com> 
26.09.2005 12:25
Please respond to
"HttpClient User Discussion"


To
<httpclient-user@jakarta.apache.org>
cc

Subject
urgent: Problem using basic authentication






Hi guys,
I am using the sample application given on the commons httpclient site for 
basic authentication. I have my server running on my own machine on 8080 
port. I have a realm called 'MyRealm'. Now when i run this application i 
get a below mentioned error.
P.S;-My basic aunthetication is only for /temp/* pages.

Sep 26, 2005 3:48:28 PM 
org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: basic authentication scheme selected
Sep 26, 2005 3:48:28 PM org.apache.commons.httpclient.HttpMethodDirector 
processWWWAuthChallenge
INFO: No credentials available for BASIC 'MyRealm'@localhost:8080

The program is as follows
public class BasicAuthHttpClient {

                 /**
                  * @param args
                  */
                 public static void main(String[] args) throws Exception {
        HttpClient client = new HttpClient();
 
        // pass our credentials to HttpClient, they will only be used for
        // authenticating to servers with realm "realm" on the host
        // to authenticate against an arbitrary realm or host change the 
appropriate argument to null.
        client.getState().setCredentials(new AuthScope("http://localhost", 
8080,"MyRealm"),new UsernamePasswordCredentials("MyRealm", "hello"));
 
 

        // create a GET method that reads a file over HTTP, we're assuming
        // that this file requires basic authentication using the realm 
above.
        GetMethod get = new GetMethod("
http://localhost:8080/sample/temp/index.html");

        // Tell the GET method to automatically handle authentication. The
        // method will use any appropriate credentials to handle basic
        // authentication requests.  Setting this value to false will 
cause
        // any request for authentication to return with a status of 401.
        // It will then be up to the client to handle the authentication.
        get.setDoAuthentication( true );

        try {
            // execute the GET
            int status = client.executeMethod( get );

            // print the status and response
            System.out.println(status + "\n" + 
get.getResponseBodyAsString());

        } finally {
            // release any connection resources used by the method
            get.releaseConnection();
        }
    }
}

Why is it saying that no credentials are avaliable.
looking forward to urgent reply...
regards



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message