问题描述
用IPV4的URI是可以访问的,如下代码stringuristring=“http://192.168.1.1/login.cgi”byte[]responseArray=myWebClient.UploadData(uriString,"POST",byteArray);但是用IPV6的URI就用UploadData就访问不成功,如下:stringuristring=“http://[fe80::1]/login.cgi”byte[]responseArray=myWebClient.UploadData(uriString,"POST",byteArray);请问大家帮帮看看该怎么解决谢谢!要怎么处理这个IPV6的uristring,才能访问成功喃另外,用IE浏览器,IPV4和IPV6都可以访问成功
解决方案
解决方案二:
privateIPAddressgetIdAddress(){//IPHostEntryipEntity=Dns.GetHostEntry(Dns.GetHostName());////IPAddressipAddr=ipEntity.AddressList[0];//IPAddressipAddr=Dns.GetHostAddresses(Dns.GetHostName())[0];//if(ipAddr.AddressFamily==System.Net.Sockets.AddressFamily.InterNetworkV6)//判断是否IP6协议//{//ipAddr=Dns.GetHostEntry(Dns.GetHostName()).AddressList[1];//}IPAddressipAddr=null;IPAddress[]arrIP=Dns.GetHostAddresses(Dns.GetHostName());foreach(IPAddressipinarrIP){if(System.Net.Sockets.AddressFamily.InterNetwork.Equals(ip.AddressFamily)){ipAddr=ip;}elseif(System.Net.Sockets.AddressFamily.InterNetworkV6.Equals(ip.AddressFamily)){ipAddr=ip;}}returnipAddr;}