【问题标题】:Spring 3.0 REST service 401 UnauthorizedSpring 3.0 REST 服务 401 未授权
【发布时间】:2011-12-14 17:39:53
【问题描述】:

我正在使用 Spring 3.0 中的 RestTemplate。当我执行这样的事情时:

 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);

【问题讨论】:

    标签: spring proxy resttemplate


    【解决方案1】:

    上面的解决方案非常有效。这是服务器端的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2022-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-19
      相关资源
      最近更新 更多