2015-09-15 142 views
1

我已經編寫了一個客戶機/服務器應用程序,正在我的本地機器上進行測試。將IPv6回送地址解析到Uri

服務器讀取客戶端的IP地址爲::1,這是一個IPv6環回地址。

不過,我以後需要重新建立這個客戶的HttpClient的連接,通過提供一個URI的BaseAddress:

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

這導致異常Invalid URI: The format of the URI could not be determined.

我怎樣才能得到的URI接受這個地址?

+0

做如何解決谷歌搜索'的IPv6來這裏URI'是一個起點http://stackoverflow.com/questions/5277060/is-there-a-standard-net-decoder-for-ipv4-and-ipv6-addresses – MethodMan

回答

4

正如其他職位提到的,解決的辦法是環繞按照IPv6地址括號與RFC 2732

var uri = new Uri("http://[::1]:8080");