Fixed HTTPS and added some test code for invalid certificates