Java basic authorization with URLConnection

Posted by zigomir on Stack Overflow See other posts from Stack Overflow or by zigomir
Published on 2010-06-01T07:24:24Z Indexed on 2010/06/01 7:43 UTC
Read the original article Hit count: 335

Filed under:
|
|
|

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!

© Stack Overflow or respective owner

Related posts about java

Related posts about web-services