Abhishek Maurya Abhishek Maurya - 2 months ago 12
HTTP Question

How to connect to sub URL using java maintaining the session?

There are two URL, suppose URL1 and URL2. URL1 can be used only by provide the proper credentials. I have completed this part by writing the code for simple authentication. However to connect to URL2, I have to maintain the session from URL1. I cannot figure this part out. It is showing response code as Forbidden!


, I have to maintain the session from URL1.

It is not likely since on any website, the session is maintained only if the first connexion is maintainted. HTTP is stateless

When you authenticate on a website, generally, you receive a token in the HTTP response (generally in the headers). After being authenticated, for each request, you must re-send that token in your HTTP requests (generally in the headers) otherwise the server considers you as unauthenticated.

So, to solve your problem, you should analyse what the server give you in headers response when it authenticates you successfully.
If you can test your scenario with a browser which owns tools to intercept request/response content, you should easily find the token information sent in the request.