Basic authentication for REST API using spring restTemplate

前端 未结 8 1253
眼角桃花
眼角桃花 2020-11-29 21:02

I am completely new in RestTemplate and basically in the REST APIs also. I want to retrieve some data in my application via Jira REST API, but getting back 401 Unauthorised.

8条回答
  •  粉色の甜心
    2020-11-29 21:11

    You may use spring-boot RestTemplateBuilder

    @Bean
    RestOperations rest(RestTemplateBuilder restTemplateBuilder) {
        return restTemplateBuilder.basicAuthentication("user", "password").build();
    }
    

    See documentation

    (before SB 2.1.0 it was #basicAuthorization)

提交回复
热议问题