RE: CORS in custom webservice in CRM Script
To resurrect an old topic that seems to still haunt me once in a while;
As mentioned earlier, a pre-flight request uses the OPTIONS method, but that does not seem to be allowed by the IIS hosting SO Online? I can see my "Access-Control-Allow-Origin" header if i'm making a POST or GET request, but OPTIONS returns 405 method not allowed...
I just discovered that in Postman - here i'm requesting the script with a POST or a GET:

as you can see, "Access-Control-Allow-Origin" is present here as i've specified it in the script.
But when i'm requesting the script with OPTIONS to simulate a pre-flight request, look what happens:

So the OPTIONS verb is simply not allowed when calling CRM Scripts?
This is the script i tested with:
%EJSCRIPT_START%
<%
#setLanguageLevel 3;
//Set HTTP headers
Map _headers;
_headers.insert("Content-Type", "application/json;charset=utf-8");
_headers.insert("Access-Control-Allow-Methods","POST,OPTIONS,GET");
_headers.insert("Access-Control-Allow-Origin","https://online.businessanalyze.com");
String posted = getCgiContent();
JSONBuilder jb;
if(posted != ''){
try{
jb.pushObject('');
jb.popLevel();
}
catch{
jb.pushObject('');
jb.addString('Status', 'Error');
jb.addString('Error', error);
jb.popLevel();
}
jb.popLevel();
_headers.insert("Status", "200 OK");
}else{
jb.pushObject('');
jb.addString('Status', 'Error');
jb.addString('Error', 'No input!');
jb.popLevel();
_headers.insert("Status", "400 NOT FOUND");
}
String h;
for (_headers.first(); !_headers.eof(); _headers.next())
h += _headers.getKey() + ": " + _headers.getVal() + "\n";
setParserVariable("ej.headers", h);
printLine(jb.getString());
%>
%EJSCRIPT_END%
Called via:
https://online2.superoffice.com/CustXXXXX/CS/scripts/customer.fcgi?action=safeParse&includeId=XXX&key=XXX