gpt4 book ai didi

java - 如何解析 java.net.SocketPermission

转载 作者:行者123 更新时间:2023-11-30 11:10:26 25 4
gpt4 key购买 nike

当我在服务器中运行 java 代码时,它会显示以下异常:

java.security.AccessControlException: 访问被拒绝 ("java.net.SocketPermission""localhost:15990""listen,resolve")

这是我的java代码:

 public String getSessionCookies(String user, String pass,String loginUrl,String phantomPath) {
StringBuilder builder=new StringBuilder();
try{
PhantomJSDriverService service = new PhantomJSDriverService.Builder().usingAnyFreePort().usingPhantomJSExecutable(new File(phantomPath)).build();

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);// not really needed: JS enabled by default
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,phantomPath);
driver = new PhantomJSDriver(service,DesiredCapabilities.phantomjs());
driver.get(loginUrl);
System.out.println(driver.getTitle());
driver.findElement(By.id("login:loginName")).sendKeys(user);
driver.findElement(By.id("login:password")).sendKeys(pass);
waitForJQueryProcessing(driver, 5);
driver.findElement(By.xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/div[2]/button[1]")).click();
Thread.sleep(10000);
driver.get("https://ecf.ca2.uscourts.gov/");
Thread.sleep(10000);
Set<org.openqa.selenium.Cookie> allCookies=driver.manage().getCookies();
for ( org.openqa.selenium.Cookie loadedCookie : allCookies) {
builder.append(String.format("%s->%s, ", loadedCookie.getName(),loadedCookie.getValue()));
//System.out.println(String.format("%s->%s, ", loadedCookie.getName(),loadedCookie.getValue()));
}
driver.close();
}catch(Exception e){
System.out.println(e.getStackTrace());
writeFile(e.toString(),phantomPath);
}
return builder.toString();
}

上面的代码在本地系统中运行完美,但是当我必须调用服务器时,它会产生上面的异常。

请提供您的建议。

谢谢

最佳答案

在您的 java.policy 文件中添加 permission java.net.SocketPermission "localhost:15990", "listen, resolve"。您可以在 jre > lib > security 文件夹中找到此文件

关于java - 如何解析 java.net.SocketPermission,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27688440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com