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