java - Unirest is caching basic authentication information -


we calling backend 2 rest services (a, b) (get method), these 2 services have different credentials (username , password), faced strange behavior:

1- if called first, authentication successful, if called b, receive forbidden (authentication failed)

then deploy application again , scenario:

2- call b first, authentication successful, if called a, receive forbidden (authentication failed):

this sample code of calling backend services:

httpresponse<string> resp;         try {             resp = unirest.get(url)                     .basicauth(username,password).asstring();             string jsonstr = resp.getbody();         } catch (exception e) {             e.printstacktrace();             throw e;         } 

any help?

i figured out. try this...

final credentialsprovider provider = new basiccredentialsprovider(); final usernamepasswordcredentials credentials = new usernamepasswordcredentials(getusername(), getpassword()); provider.setcredentials(authscope.any, credentials); final httpclient httpclient = httpclientbuilder.create().setdefaultcredentialsprovider(provider).build();  unirest.sethttpclient(httpclient); response = unirest.get(url).querystring(queryparameters).asjson(); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -