My SharePoint client JavaScript is calling an external REST API URL, using the code pattern below
$.ajax({
type: "POST",
url: 'https:\\theexternal.domain......,
contentType: "application/json",
headers: {
'Accept' : "application/json, */*;",
'Authorization': 'Basic ' + btoa(username + ':' + password)
},
data: JSON.stringify({
.
.
.
}),
success: success,
error: error
});
We have changed the web.xml
configuration file of the external domain server, to include the code:
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
as per the directions on https://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter.
However, the AJAX POST is still returning the error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https:\theexternal.domain...... This can be fixed by moving the resource to the same domain or enabling CORS.
What have we missed?