I don't know exactly which part causes the crash, but I assume you'd be familiar with it. You should use a try/catch blocks. I assume some kind of exception is thrown when it fails to connect. Put the code you think presents the issue in the "try" block. Then put what you want to do when the issue comes up in the "catch" block. This way, when it throws an exception, you can handle it rather than crash.
It's probably this line: host = gethostbyname(url.c_str());
gethostbyname returns null if resolution fails, which is something that will usually happen if you don't have an internet connection.