我正在尝试使用Apache Wink框架在Java中消费一个RESTful webservice,需要通过我的学校Web代理进行身份验证。
ClientConfig clientConfig = new ClientConfig();
clientConfig.proxyHost("proxy.school.com");
clientConfig.proxyPort(3128);
//nothing to set username and password :(
RestClient client = new RestClient(clientConfig);
Resource resource = client.resource("http://vimeo.com/api/v2/artist/videos.xml");
String response = resource.accept("text/plain").get(String.class);
我还尝试过使用 BasicAuthSecurityHandler
,但似乎它被用于直接对Web服务器进行身份验证,而不是Web代理。
BasicAuthSecurityHandler basicAuthHandler = new BasicAuthSecurityHandler();
basicAuthHandler.setUserName("username");
basicAuthHandler.setPassword("password");
config.handlers(basicAuthHandler);
仍然以HTTP 407错误代码失败:需要代理身份验证。
我已经尽力搜索了最佳方法,但没有更好的方法能够通过Web代理从Java客户端消费Web服务。如果有其他想法,请随意回复。