Patched to use SSL if requested.