4

我正在尝试通过需要身份验证的学校网络代理使用Apache Wink 框架在 java 中使用宁静的网络服务

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 服务更好的方法了,如果有人有其他想法,请随时回复

4

2 回答 2

3

好的,这很难,但我找到了!我用Fiddler记录了从我的浏览器发出的 HTTP 请求,并在阅读了关于 HTTP/1.1的大量文档(如RFC 2616 )后发现Proxy-ConnectionProxy-Authorization我正在寻找的内容

因此,我将发送到我的 java 代码中的值复制粘贴:

resource.header("Proxy-Connection", "Keep-Alive");
resource.header("Proxy-Authorization", "Basic encodedString");

encodedString我的浏览器发送的内容在哪里: username:passwordbase64 编码

现在它完美地工作了:)

于 2010-06-11T16:25:58.103 回答
1

此问题已作为 [1] 提出,并且已通过添加 Apache Wink 客户端开发人员可用的 ProxyAuthSecurityHandler 得到解决。

[1]:https ://issues.apache.org/jira/browse/WINK-292 Apache Wink JIRA 问题 WINK-292

于 2010-07-26T18:38:50.340 回答