I'm trying to update my Abdera client application to use Basic authentication. Here is my basic code for initializing the client:
Abdera abdera = new Abdera();
AbderaClient client = new AbderaClient(abdera);
AbderaClient.registerTrustManager(); // needed for SSL
client.addCredentials(AuthScope.ANY_HOST, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME, new UsernamePasswordCredentials(apiKey + "%" + userName, password));
When I use the client to PUT however I get a 401: Unauthorized error. I've tested the same URL and credentials using RESTClient and they work fine. Any suggestions as to why it would not authorize properly?
We unfortunately do not have any abdera experts on hand who may have more intimate knowledge of this language. However, I believe that the correct syntax for ading a credential should be as follows (this could be the cause of your 401 unauthorized):
client.addCredentials("http://api.constantcontact.com", "realm", "basic", new UsernamePasswordCredentials(apiKey + "%" + userName, password));
The realm option should not matter in this case, however the domain and the scheme are important to set. I am unsure how the headers are set for requests made with ANY_HOST and ANY_SCHEME and this may affect whether or not the API will accept the connection.