Manoj K · Apr 1, 2017

How to enable CORS in Cache Rest Services


I tried to access one server to another server in Cache Rest Service, I tried 

Parameter HandleCorsRequest = 1;


<Route Url="/data/:first/:second" Method="GET" Call="GetData" Cors="true"/>

But not working,

Can anyone tell me the solution??

Thanks in advance!!

1 1,305
Discussion (5)0
Log in or sign up to continue
Parameter HandleCorsRequest = 1;

Should be enough.


Anyway, what error are you getting?

This error I got

HttpRequest cannot load http://localhost:57772/api/project. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:57773' is therefore not allowed access. The response had HTTP status code 401.

You need to give access to the web-application.

You can put some code in the OnHandleCorsRequest to debug or monitor the CORS handling :

/// This is the CORS request handler. User should override this method in their subclass
/// if they don't want the default behavior
ClassMethod OnHandleCorsRequest(pUrl As %String) As %Status
    #; The default implementation is simply to dispatch to the
    #; default handler
    Set tOrigin=$Get(%request.CgiEnvs("HTTP_ORIGIN"))
    Set ip = $Get(%request.CgiEnvs("REMOTE_ADDR"))
    Set method = $Get(%request.CgiEnvs("REQUEST_METHOD"))
    set ^debug($i(^debug))=$lb($ZD($H,8),$ZT($P($H,",",2)),pUrl,tOrigin,ip,method)
    Quit ..HandleDefaultCorsRequest(pUrl)

Still having problems ?

Try something like this...

Do %response.SetHeader("Access-Control-Allow-Origin","*")

Before your application response !