我们正在云中使用 Azure 进行工作,其中我们有 3 个部分:一个用于前端( Angular ),一个用于后端(java),最后一个用于数据。目前,我们面临着一个问题,无法让我们将 Angular 与 Java 代码连接起来。 我们正在对 Angular 应用程序和 Rest 服务通信进行 CORS 验证。此问题仅发生在云端,但不会发生在我们的本地设置中。
错误消息:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://crecemasbcpdesa.lima.bcp.com.pe' is therefore not allowed access. The response had HTTP status code 504.
最佳答案
您是否在 Java EE 应用中启用了 CORS 支持?像这样的东西:
@Provider
public class CORSResponseFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
MultivaluedMap<String, Object> headers = containerResponseContext.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
headers.add("Access-Control-Allow-Headers", "Content-Type");
}
}
关于javascript - 使用 Azure 中的 Angular 应用程序和 Rest 服务进行 CORS 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40790470/