If the code with localhost you are able to connect to that URL and get the result, but when you are live with same code then you get that error of port which means that the port 80 and 443 at your hosting end is blocked which is resulting in connection time out.
Kindly contact to your hosting partner and ask to unblock the same.
This also happens due to the firewall security setting to allow to make the connection with the URL.
Please refer the link: https://technet.microsoft.com/en-us/library/ms345310(v=sql.100).aspx