Skip to Content
0
Jun 21, 2022 at 11:35 AM

How to get Cookies of HTTP Request in BAS?

259 Views

Hello,

im facing the problem to send a put http request to an odata service. It works in Postmen with following steps:

1) Send a Get-Request with header: x-csrf-token : fetch and safe the token

2) Send a Put-Request with header: x-csrf-token : token of Get-Request

I noticed, that postmen got the same SessionID Cookie in the Get and the Put Request.

Now I want to build a fiori App, where I want to call the Odata Service.

1) I send a HTTP Get-Request with the fetchAPI whit header x-csrf-token : fetch and safe the token

2) Send a Put-Request with header: x-csrf-token : token of Get-Request.

Now I get a 403 Forbidden Error.

I checked the network tab in the dev tools of chrome and i compared the cookies of both requests. Theire sessionIDs was not equal so i thought I just need to read the cookies of the Get Request and set a Cookie Header in the Put Request to guarantee that both Requests got the same SessionID.

However this does not seem to be possible. If I read the response Header of my Get Request, i does not get the set-cookie header, although it is shown in the network tab. If i call document.cookies i just get an empty string.

So my first Problem is, that I cant read the cookies of my get request. Due to my internet research, it seems like it doesnt work becauce of cross-side problems. But im not sure about this and I do not know how I can solve this error.

In addition to that, im not able to change the cookie header in my Put request. If I set a header:

Cookie: SAPSESSIONID_<someValue> : SessionID (e.g my Postman SessionID), this headerline is not shown in my Network Tab and the Session ID of my Put Request is not the ID i wanted to be setted.