我必须使用用户名和密码连接到 https URL 才能读取文件。我无法连接到服务器(请参阅下面的错误日志)。我没有太多 Java 经验,因此我需要有关此代码的帮助。
import lotus.domino.*;
import java.net.*;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
String username = "123";
String password = "456";
String input = username + ":" + password;
String encoding = new sun.misc.BASE64Encoder().encode (input.getBytes());
//Open the URL and read the text into a Buffer
String urlName = "https://server.org/Export.mvc/GetMeetings?modifiedSince=4/9/2010";
URL url = new URL(urlName);
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", String.valueOf (encoding.length()));
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setAllowUserInteraction(true);
connection.setRequestProperty("Authorization", "Basic " + encoding);
connection.setRequestProperty("Cookie", "LocationCode=Geneva");
connection.connect();
BufferedReader rd = null;
try{
rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
} catch (IOException e) {
System.out.println("Read failed");
System.exit(-1);
}
String line;
while((line = rd.readLine()) != null) {
System.out.println(line.toString());
}
rd.close();
connection.disconnect();
} catch(Exception e) {
e.printStackTrace();
}
}
}
抛出异常:
java.security.AccessControlException: Access denied (java.lang.RuntimePermission exitVM.-1)
at java.security.AccessController.checkPermission(AccessController.java:108)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at COM.ibm.JEmpower.applet.AppletSecurity.superDotCheckPermission(AppletSecurity.java:1449)
at COM.ibm.JEmpower.applet.AppletSecurity.checkRuntimePermission(AppletSecurity.java:1311)
at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1611)
at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1464)
at java.lang.SecurityManager.checkExit(SecurityManager.java:744)
at java.lang.Runtime.exit(Runtime.java:99)
at java.lang.System.exit(System.java:275)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)