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;
本文介绍了一个简单的跨域请求处理方法,通过设置HTTP响应头来允许跨域访问。具体包括设置字符集为UTF-8,内容类型为application/json,并通过自定义头部信息允许所有源进行跨域访问。

3054

被折叠的 条评论
为什么被折叠?



