Today, I have to find the way to authenticate my application with web server via HTTP basic authentication. And this is how it is done.
1. Pack username and password into this format
username:password
such as
janitor:topsecret
2. Then encode it with base64 so that our sample will become
amFuaXRvcjp0b3BzZWNyZXQ=
3. Add "Authorization" header to HTTP session
Authorization: Basic amFuaXRvcjp0b3BzZWNyZXQ=
References
http://en.wikipedia.org/wiki/Basic_access_authentication