add error checking to connect
fix memory leak
Fix memory leak fix
add basic authentication to http request