我创建了一个露天网页脚本,可以使用以下网址进行访问:
http://localhost:9191/alfresco/s/search/item/ {itemIid} 例如: http://localhost:9191/alfresco/s/search/item/it0001
当我直接从浏览器地址栏中点击时,它可以正常工作,但是当我从我的角度服务中调用它时,我会收到CORS错误
无法加载http://localhost:9191/alfresco/s/search/item/it0001:对预检请求的响应未通过访问控制检查:所请求的资源上没有'Access-Control-Allow-Origin'标头。因此,不允许访问来源“ http://localhost:4201”。
我的棱角部分是这样的:
convert1(itemId:string){
var headers = new Headers();
headers.set('Content-Type','*');
headers.set('Access-Control-Allow-Origin','*');
headers.append('Authorization','Basic zfsdfsdfsdfdsf=');
return this.http.get(http://localhost:9191/alfresco/s/search/item/it0001,{headers:headers});
}
在露天仓库中,我在网页脚本代码中添加了以下内容,但这没有帮助。
response.setHeader("Access-Control-Allow-Origin", "*");
我可以在我的alfresco-repo amp插件中进行哪些更改,以便可以避免此错误。
任何见识都将受到高度赞赏。
--------在Jeff Potts回答后-----
1. D:\abcd-app-repo\target\amp-war\WEB-INF\web.xml
<!-- CORS Filter Begin -->
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowSubdomains</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, HEAD, POST, PUT, DELETE, OPTIONS</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>origin, authorization, x-file-size, x-file-name, content-type, accept, x-file-type</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>3600</param-value>
</init-param>
</filter>
<!-- CORS Filter End -->
<!-- Enterprise filter placeholder -->
<filter-mapping>
<filter-name>Global Localization Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<!-- CORS Filter Mappings Begin -->
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/api/*</url-pattern>
<url-pattern>/service/*</url-pattern>
<url-pattern>/s/*</url-pattern>
<url-pattern>/cmisbrowser/*</url-pattern>
</filter-mapping>
<!-- CORS Filter Mappings End -->
答案 0 :(得分:0)
尝试以下步骤: