Spring RestTemplate gives "500" error but same URL, credentails works in RestClient and Curl
I would suggest to create your HttpComponentsClientHttpRequestFactory
and pass it to your RestTemplate
as described below:
ClientHttpRequestFactory requestFactory = new
HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());
RestTemplate restTemplate = new RestTemplate(requestFactory);
By this way, you would avoid server-side issues (like facing error code 500) when testing your application.
I had the same issue that worked in my local environment and not on the server.
It is a good practice to pass HttpClients.createDefault()
to your HttpComponentsClientHttpRequestFactory
while constructing it since by default, this factory uses system properties to create HttpClient
for your factory and that may cause lots of pain in real server environment. You may also pass your custom HttpClient
.
RestTemplate header Accept problem
--> accept - text/plain, application/json, */*
HttpClient 4.x header Accept
--> accept - application/json
so i fixed
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
http://www.manning-sandbox.com/message.jspa?messageID=119733
I have also faced a situation where server response was "500 Internal server error"
Though I have received success response from Postman for the same parameter value. So the problem was not in server side.
The problem was typo in parameter name, mismatch spelling between application parameter and server parameter
Server parameter -> requestLabel
Application parameter -> requestLable
Hope someone new like me get help from this.