1. Resolve hostname and remember the response
2. Verify that the response does not contain any addresses in a private IP space, or any other IP that is only accessible to you
3. Use the IP from step 1 when establishing a connection
With other solutions, you might end up being vulnerable to DNS rebinding attacks.
Bonus points for doing all your URL fetching in some sort of sandbox that enforces these access rules.