The full message is:
"Invalid URI : The hostname could not be parsed".
I get this using the URIBuilder class.
Since it was complaining about the hostname I checked the DNS, I checked that I could ping it, I tried the IP address etc. etc.
Eventually worked out that it was because the password contained special characters.
You are apparently supposed to URL encode them.
Just changed the password to use letters and numbers and all was well.
Somewhat misleading error message :-)