cancel
Showing results for 
Search instead for 
Did you mean: 

Service layer - Send http request in angular with current session ID

tomersha717
Explorer
0 Kudos
7,376

Hi,

I'm trying to fetch some data after I did log in and store the Id Session to send it on any request

for example, get items request.

I do not understand how to pass the in the header request the Cookie: B1SESSION=PTRzIjYK-weN6-1Lx1-ZG0J-3ARxfjcU0Shy; ROUTEID=.node1

I have tried some methods and got all kinds of errors

this is my code

getItems(){    
    let headers = new HttpHeaders();
    headers = headers.append('Cookie', 'B1SESSION=' + localStorage.getItem('B1SESSION') + '; ROUTEID=.node3');
    console.log(headers);
    return this.http.get<Item[]>(this.urlItems, {headers: headers} );
    
  }<br>

What am I doing wrong?

Tomer.

Accepted Solutions (0)

Answers (5)

Answers (5)

tomersha717
Explorer

I found a solution, need to send with all requests this line code { withCredentials: true }

Regards,
Tomer

rahuljain257
Participant

Great to hear to that !!!

tomersha717
Explorer
0 Kudos

1. SQL

2. YES include 'get' items method

3. Yes, still working on it.

I managed to get the SessionId in the login method, but still don't know how to send it with items request

Tomer.

tomersha717
Explorer
0 Kudos

It's already set like this and still doesn't work

<ifmodule mod_headers.c>
Header edit Set-Cookie ^(.*)$ $1;Secure;SameSite=None
</ifmodule>

I save the response login as cookies like describe in the documentation

Can't find anywhere how to send it or how to send in the http get items request

maybe it will solve the problem

please help!!!

rahuljain257
Participant
0 Kudos

Hey, One Quick question,

1. URL is showing as localhost:50000 is it SQL / HANA ?

2. Is it working perfectly through Postman client ?

3. Have tried to use Sample applications provided by @ Ralphive ? If yes what is the output you got pls share

tomersha717
Explorer
0 Kudos

I'm using chrome

Without handling the header I get 401 Unauthorized

any more ideas?

Tomer.

b1session.png

rahuljain257
Participant
0 Kudos

Please check the resolution here - Click here

rahuljain257
Participant
0 Kudos

If you're using browser then session id and other details stored in cookies and you don't have send those details in request header, its handled internally.

But if you're using Windows App then you need pass the details separately.

Also the same details you can find it in Service Layer documentation

Just find this link for more information - Click here