@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