@alex:好的......我设法按照您的建议建立了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..
...它抛出以下异常...登录之前出现相同的异常...我该如何纠正?
Server returned HTTP response code: 401 for URL: https://www.example.com/account.aspx