4

I've written a client/server application which I'm testing on my local machine.

The server reads the IP Address of the client as ::1 which is an IPv6 loopback address.

However, I need to re-establish an HttpClient connection to this client later, by providing a Uri's BaseAddress:

  var originalAddress = "::1";
  var client = new HttpClient() { BaseAddress = new Uri(originalAddress) };

This results in the exception Invalid URI: The format of the URI could not be determined.

How can I get the Uri to accept this address?

Daniel Minnaar
  • 5,865
  • 5
  • 31
  • 52
  • do a google search on how to resolve `IPv6 to a URI` here is a starting point http://stackoverflow.com/questions/5277060/is-there-a-standard-net-decoder-for-ipv4-and-ipv6-addresses – MethodMan Sep 15 '15 at 14:53

1 Answers1

6

As mentioned in other posts, the solution is to wrap brackets around the IPv6 address in accordance with RFC 2732:

var uri = new Uri("http://[::1]:8080");
Daniel Minnaar
  • 5,865
  • 5
  • 31
  • 52