2010-06-11 66 views
4

我想通過我校網頁代理需要認證消耗使用Apache Wink framework在Java中RESTful Web服務通過Web代理消費RESTful 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錯誤代碼:需要代理身份驗證。

我GOOGLE了我所能的最好,沒有想出了更好的通過網絡代理消耗從Java客戶端Web服務,如果有人有另外一種想法,隨時應對

回答

3

好了,這是相當困難的,但我找到了 !我登錄,正在從我的瀏覽器製造與Fiddler的HTTP請求,並發現閱讀像RFC 2616大量的文檔有關HTTP/1.1

後的Proxy-ConnectionProxy-Authorization是什麼,我一直在尋找所以我複製粘貼的值是分別被送進我的Java代碼:

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

其中encodedString是什麼,是被我的瀏覽器發送的:username:password base64編碼

它現在的作品完美:)

1

此問題是由於[1]提出的,並且自從Apache Wink客戶端開發人員添加了可用的ProxyAuthSecurityHandler以來已得到解決。

[1]:https://issues.apache.org/jira/browse/WINK-292阿帕奇表情JIRA問題WINK-292