I make a request to the https URL with the postman, I get 400 response and data without any certification config. While I make the same request with restTemplate I get 404 not found with the same url. postman body :
{
"Request": {
"usernamenull": "",
"passwordnull": ""
},
"username": "iceicebaby",
"password": "12345"
}
and Java code:
HttpHeaders headers= new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Authorization","Basic ***");
headers.add("Accept", "*/*");
RequestBodyModel request = new RequestBodyModel();
request.setRequest(new UserRequest("",""));
request.setUsername(userName);
request.setPassword(password);
HttpEntity<RequestBodyModel> requestEntity = new HttpEntity<>(request,headers);
String response = restTemplate.postForObject(url,requestEntity,String.class);
any help appreciated, thanks.
EDIT: I changed my code to :
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST,requestEntity,String.class);
and I get 302 redirect error(Location: same url, server: 'ACB') while postman works perfectly.
The difference between postman and restTemplate is because of their ways to handle redirect.
Postman
Postman automatically redirect your request. As you can see in this screenshot, I think you're postman's automatic redirect option will be turned on too.
restTemplate
But, restTemplate doesn't automatically redirect your requests.
Solution
1. Configure restTemplate to follow redirect
.
2. manually handle redirect