1

We are trying to access the Lithium Rest Api (its a https site) through Spring Rest Template as below

           `String plainCreds = lswUserName + ":" + lswPassword;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity<String> request = new HttpEntity<String>(headers);
        ResponseEntity<String> sRawResp = restTemplate.exchange(completeURL.toString(), HttpMethod.GET, request, String.class);'

Above code always gives

org.springframework.web.client.HttpClientErrorException: 401 Unauthorized Exception

There were no issues when invoking the same web service through postman, however when ever accessed through java code, getting the above 401 unauthorized exception

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Just check your `base64Creds` is same as what you are using in postman – Hemant Patel May 08 '18 at 18:59
  • What does the packet look like? Also, take care not to post the hash of a real password here. – Stephan May 08 '18 at 19:00
  • Any special chars in name or password? – Turo May 08 '18 at 19:26
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer May 08 '18 at 22:15
  • Yes, I have special characters # in the password and @ in the username, would be any issue?? – user3278232 May 09 '18 at 06:13
  • Hi Hemant, the base64creds have encrypted username and password the same way as postman did.. – user3278232 May 09 '18 at 06:14

0 Answers0