Close the output stream before closing connection

This was causing "Unexpected end of stream" errors when trying to execute any POST requests (such as posting comments).