addded urlencode for username and password

urlencode code is from http://stackoverflow.com/a/10660730