Spring 3.0 REST service 401 Unauthorized
-
16-03-2021 - |
Question
I'm using RestTemplate from Spring 3.0. When I execute something like this:
restTemplate.getForObject(url, Map.class);
I got:
org.springframework.web.client.RestTemplate- GET request for "http://somewhere.com..." resulted in 401 (Unauthorized); invoking error handler
That's cos I need to set up a Proxy address. How can I set a proxy with Spring RestTemplate?
This is what I did till now without any luck:
HttpHost proxy = new HttpHost("proxy.somwhere.com",9999);
HttpClient httpClient = new HttpClient();
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
CommonsClientHttpRequestFactory requestFactory = new CommonsClientHttpRequestFactory(httpClient);
// requestFactory.getHttpClient().getHostConfiguration().setProxy("proxy.somwhere.com",9999);
restTemplate.setRequestFactory(requestFactory);
Solution
The solution above is perfectly working. It was a server side problem.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow