Dear All;
with TIdHTTPServer, how do I add the "Access-Control-Allow-Origin" header?
My intuitive move with VCL was:
but when I test it with simple HTML in web browser:
browser throws "No 'Access-Control-Allow-Origin' header is present...". The TIdHTTPServer server does get this request with no complains of any kind.
BTW, if I insert my URL "http://127.12.34.56:7890/qwe" into the browser's address bar and press Enter - everyone is happy even if the server does not add an extra header.
TIA/Boba
with TIdHTTPServer, how do I add the "Access-Control-Allow-Origin" header?
My intuitive move with VCL was:
Code:
TIdHTTPServer *IdHTTPServer;
//...
void __fastcall
TForm1::IdHTTPServerHeadersAvailable(TIdContext *AContext, const UnicodeString AUri,
TIdHeaderList *AHeaders, bool &VContinueProcessing)
{
AHeaders->Add("Access-Control-Allow-Origin: *");
VContinueProcessing = true;
}
Code:
<!DOCTYPE HTML>
<HTML>
<BODY>
<BUTTON onclick="myFunction()" type="button">TEST</BUTTON>
<SCRIPT>
function myFunction(){
let o = new XMLHttpRequest();
//the IdHTTPServer is bound to "http://127.12.34.56:7890"
o.open("GET", "http://127.12.34.56:7890/qwe", false);
o.send();//No 'Access-Control-Allow-Origin' header is present ...
};
</SCRIPT>
</BODY>
</HTML>
BTW, if I insert my URL "http://127.12.34.56:7890/qwe" into the browser's address bar and press Enter - everyone is happy even if the server does not add an extra header.
TIA/Boba