reimplemented upload to use XMLHTTPRequest instead of raw TCP sockets
to fix issue #538