Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
adding Access-Control-Allow-Origin header
#1
Dear All;
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;
}
but when I test it with simple HTML in web browser:
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>
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
Reply


Messages In This Thread
adding Access-Control-Allow-Origin header - by Boba TC - 08-20-2022, 04:37 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)