delphi httpserver 跨域

uses

IdBaseComponent,
  IdComponent, IdCustomTCPServer, IdCustomHTTPServer, IdHTTPServer, IdContext,
  IdHTTPHeaderInfo,
  IdHeaderList, IdGlobalProtocols

 

procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  CustomHeadersStringList: TIdHeaderList;
begin
  AResponseInfo.CharSet := 'UTF-8';
  AResponseInfo.ContentType := 'application/json';

  CustomHeadersStringList := TIdHeaderList.Create(QuoteHTTP);
  CustomHeadersStringList.Add('Access-Control-Allow-Origin:*');

  AResponseInfo.CustomHeaders := CustomHeadersStringList;

  AResponseInfo.ContentText := '跨域';

  CustomHeadersStringList.Free;
end;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章