简体   繁体   中英

Maintain session when calling a REST service from Java

I am trying to call a web services which requires certain authorization(Login) from user. Is it possible to maintain a session for that i can call those web services in java console base application.

for example:- I have one rest API in which I can get the investor's investment by passing the investor id. To get the investment details by that particular investor user has to login(that is also another web service(i have create a api for login which i am calling to authorize the user)). Can we pass header along with the get request if we can't maintain a session for that?

Please tell me. if I am not clear please comment below. Thank You.

Since it's a vague problem, I will try to give some pointers about a 'generic' solution. Your REST service can return an object linked with the credentials of the user. It's what's called a 'cookie'. Then, at each call, you just have to resend the cookie, and you have the credentials...

See: http://docs.oracle.com/javaee/7/api/javax/servlet/http/Cookie.html http://www.java2s.com/Tutorial/Java/0400__Servlet/GetSetCookie.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM