How to connect to the internet from Terminal when using a proxy with authentication
Terminal does not use proxy settings configured in the network preferences pane because it doesn't do any connection. Terminal just let you fire commands which will use the network in different ways.

When setting your http_proxy and https_proxy environment variables should not include the http: or https: prefixes.

Therefore the environment variable in your case should read:

http_proxy=username:password@proxyserver:port


Note: many old programs have issues with connecting through proxy servers which require authentication before connecting.

Additional Tip:

Due to our infrastructure we found it much easier to have users run SquidMan locally and have it configured to connect to our main proxy. This allows the local machine to act as a proxy directly, and eliminates a lot of authentication issues etc when using proxy servers on Mac machines, especially in a mixed and AD environments.

In the case of using this method our http_proxy and https_proxy would be:

http_proxy=localhost:3128