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

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -