2013-03-23 161 views
0

我正在嘗試使用Java對使用本機登錄提示的瀏覽器進行HTTPS調用。Java本機瀏覽器登錄提示

http://blog.stevensanderson.com/2008/08/25/using-the-browsers-native-login-prompt/

目前我使用的是下面的HTTP和它工作正常,其他網站,因爲我知道要放在參數...但它未能對上述類型的登錄(我不知道如何捕捉參數......這是一個登錄彈出up..or如果這是即使是正確的做法)....任何想法?..感謝

HttpUtility.sendPostRequest(requestURL, params); 
String[] response = HttpUtility.readMultipleLinesRespone(); 

回答

0

服務器應以您的第一個請求作出迴應一個WWW-Authenticate標題和一個401的狀態。標題將包含它期望的認證類型的細節。

然後,您可以在以正確的格式將Authorization標頭添加到請求後重試。

0

@alex:OK ...我設法讓HTTPS連接下您的建議與此:

URL url = new URL("https://www.example.com/Login"); 
URLConnection urlConnection = url.openConnection(); 
urlConnection.setRequestProperty("Authorization", "Basic " + authString); 
InputStream is = urlConnection.getInputStream(); 
InputStreamReader isr = new InputStreamReader(is); 

//then I read the input stream.. 

但是,當我試圖讓另一個連接(比如去登錄後不同的網頁)與這個代碼在另一種方法......採取的URLConnection作爲參數:

//Below is in a method called account(URLConnection urlConnection) 

URL url = new URL("https://www.example.com/account.aspx"); 
urlConnection = url.openConnection(); 
InputStream is = urlConnection.getInputStream(); 
InputStreamReader isr = new InputStreamReader(is); 

//again I read the input stream.. 

...它拋出以下異常......同樣的異常登錄我in..how可以糾正過嗎?

Server returned HTTP response code: 401 for URL: https://www.example.com/account.aspx