You enter all the correct data, double check you entered the correct data, click on the "Apply Settings" and after all the fuss all you get is this exception in the log file:
What's the problem you might ask.
The hosts file.
That's right, the hosts file. The guy at C:\Windows\System32\Drivers\etc.
You open this file and find something like this in it:
It's actually not important what URL was mapped to 127.0.0.1 there, as soon as you have ANY URL mapped to 127.0.0.1 in the hosts file you'll get the exception above.
Why? I have no idea. We used the IP and not name or the FQDN of the controller in the agent configuration, so it didn't have to do any DNS name resolution at all, but it did. And even then, our controller IP address was not mentioned anywhere in the hosts file, so go figure.
So how to solve it? Simply remove all the mappings for the 127.0.0.1 from the hosts file on the agent and try to register the agent again (restart the agent service to make sure it gets the new hosts file). It should connect now or at least bring some other exception.
And before you go - do the same on the test controller or you might get similar exceptions there.