#1 Today 11:44:01

Kabiri
Member
Registered: 2024-06-22
Posts: 59

Setting Cookie in Response Header with RawJSON Output Not Working

I have created a server and interface that work well, and my function returns RawJSON output. In that function, I want to send a cookie in the header along with the response.

For this purpose, I used the following code:

var Ctxt: TRestServerURIContext;
Ctxt := CurrentServiceContext.Request;
Ctxt.Call^.OutHead := Trim(Ctxt.Call^.OutHead) + #13#10 + ...

However, it does not appear in the Response Headers section of the browser.

Where is the problem?

Last edited by Kabiri (Today 12:11:03)

Offline

#2 Today 13:09:53

ttomas
Member
Registered: 2013-03-08
Posts: 149

Re: Setting Cookie in Response Header with RawJSON Output Not Working

You can try with
Ctxt.OutCookie['myCookie']:='MyValue';
also check httpServer.AccessControlAllowOrigin := ... if cross origin is involved
For cross origin cookie I use
Ctxt.OutCookie['refreshtoken']:=RefToken+'; SameSite=None; Secure; HttpOnly';

Offline

#3 Today 13:35:05

Kabiri
Member
Registered: 2024-06-22
Posts: 59

Re: Setting Cookie in Response Header with RawJSON Output Not Working

big_smile

ttomas wrote:

You can try with
Ctxt.OutCookie['myCookie']:='MyValue';

Thanks a lot, that really helped. It’s working now.

Offline

Board footer

Powered by FluxBB