If you want to send a request with spring you can do
//first create e restemplate variable
RestTemplate restTemplate=new RestTemplate();
//you can create and edit header
HttpHeaders header= new HttpHeaders();
header.add("Authorization", "*****************");
header.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
header.add("Accept", "application/json");
//you can create and edit body to
MultiValueMap<String, String> body= new LinkedMultiValueMap<String, String>();
body.add("grant_type", "client_credentials");
HttpEntity<MultiValueMap<String, String>> requeteHttp =new HttpEntity<MultiValueMap<String, String>>(body, header);
//After you can create a request
ResponseEntity<Response_class> reponse = restTemplate.postForEntity("your api link", requeteHttp , Response_class.class);
//if you want to send a get request you can edit postForEntity to get
About Response_class
if you know the return type of the request, you can create a class and use it here, otherwise you can use string instead
if your request returns a json like this
{
"token_type":"***",
"access_token":"***",
"expires_in":"***",
}
you can create a Response_class controller(class) and call it like we did above otherwise you can use string instead
public class Response_class{
private String token_type;
private String access_token;
private String expires_in;
public Response_class(String token_type, String access_token, String expires_in) {
this.token_type = token_type;
this.access_token = access_token;
this.expires_in = expires_in;
}
public Response_class() {
}
public String getToken_type() {
return token_type;
}
public void setToken_type(String token_type) {
this.token_type = token_type;
}
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getExpires_in() {
return expires_in;
}
public void setExpires_in(String expires_in) {
this.expires_in = expires_in;
}
}