【发布时间】:2011-09-07 23:17:18
【问题描述】:
我正在使用 GWT 创建一个 Web 应用程序,服务器向客户端提供服务。在此服务中,它必须生成一个 HTTP 请求到另一个具有身份验证的服务器。以下代码描述了如何发出请求:
public int request()
{
Authenticator.setDefault(new MyAuthenticator(username, password));
try {
URL url = new URL(url_string);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Content-Type", "text/xml");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(buildRequest());
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
//the rest is to handle the response ...
} catch (Exception e) {
//handle exception
}
}
MyAuthenticator 是按照建议的here 实现的,我测试了代码,它就像一个魅力,但是当我尝试将它合并到 GWT 项目中时,我遇到了一个异常:
//huge stack trace above ... what is important is the following
Caused by: java.security.AccessControlException: access denied (java.net.NetPermission setDefaultAuthenticator)
有什么办法解决这个问题吗?
【问题讨论】:
标签: java exception gwt httprequest policy