There is no problem in your code - it's fine and working!
Most probably the firewall is blocking 80
port and this is why you can't connect.
Check your connection from the console and see what you get:
ping google.com
EDIT 1:
Most likely you have a problem in your /etc/resolv.conf
or /etc/hosts
. To solve this you could refer to: Ping: Unknown host. If you can't just post output of those files and we'll see of what I could do!