Java basic authorization with URLConnection
- by zigomir
Hello!
I'm opening a connection to WebService with an URLConnection class. I also set request property for basic authorization like this:
c.setRequestProperty("Authorization", "Basic " + usernameAndPasswordEncoded);
Where c is an object of type URLConnection. So this is client side of WebService call. Now on server side I need to get username from session:
User user = (User) request.getSession().getAttribute("user");
But this won't get an username. Also if I look through debug mode, I see an anonymous userName in HttpSession object.
What to do to solve this problem, so that username is sent through client to WebService server for authorization?
Thanks everyone!