0
我從Spring 3.0使用RestTemplate。當我執行這樣的事情:Spring 3.0 REST服務401未授權
restTemplate.getForObject(url, Map.class);
我:
org.springframework.web.client.RestTemplate- GET request for "http://somewhere.com..." resulted in 401 (Unauthorized); invoking error handler
那是因爲我需要設置一個代理服務器地址。我如何使用Spring RestTemplate設置代理?
這是我做的到現在爲止沒有任何的運氣:
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);