/// <summary> /// 通过网页重定向获取 <see cref="Wlan_eduManager"/> 实例。 /// </summary> /// <returns>Wlan-edu 管理器实例。</returns> public static Wlan_eduManager CreateManagerFromRedirection() { string url; Encoding encoding = Encoding.UTF8; HtmlDocument document; // 通过重定向获取登录地址。 url = "http://1.1.1.1/"; document = new HtmlDocument(); document.Load(HttpRequestUtil.GetHtmlContentStreamReader(url, encoding)); string refresh_content = document.DocumentNode.SelectSingleNode(@"html/head/meta[@http-equiv='refresh']")?.GetAttributeValue("content", null); ; // 获取登录地址。 url = Regex.Match(refresh_content.Split(';')[1], @"url=(?<Url>\S*)").Groups["Url"].Value; var queryArgs = Regex.Matches( new Uri(url, UriKind.Absolute).Query, @"(?<=^\?|&)(?<Key>\w+?)=(?<Value>\S*?)(?=&|$)" ) .OfType <Match>() .ToDictionary( (match => match.Groups["Key"].Value.ToLower()), (match => match.Groups["Value"].Value) ); string wlanAcName = queryArgs["wlanacname"]; string wlanUserIp = queryArgs["wlanuserip"]; ; return(new Wlan_eduManager(wlanAcName, wlanUserIp, url, encoding)); }