在現(xiàn)在的項目中,使用到uri的部分較多。
創(chuàng)新互聯(lián)自2013年起,先為襄州等服務(wù)建站,襄州等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為襄州企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。uri的解析方法:
public static Uri ReturnUri(this string val) { if (string.IsNullOrEmpty(val)) { throw new ArgumentNullException(val); } try { UriBuilder uri; if (val.StartsWith("http://", StringComparison.Ordinal)) { uri = new UriBuilder(val); } else if (val.StartsWith("https://", StringComparison.Ordinal)) { uri = new UriBuilder(val); } else if (val.Contains(":")) { var split = val.Split(':', '/'); int port; int.TryParse(split[1], out port); uri = split.Length == 3 ? new UriBuilder(Uri.UriSchemeHttp, split[0], port, "/" + split[2]) : new UriBuilder(Uri.UriSchemeHttp, split[0], port); } else { uri = new UriBuilder(Uri.UriSchemeHttp, val); } return uri.Uri; } catch (Exception exception) { throw new Exception(exception.Message, exception); } }
2.uri解析的重載:
public static Uri ReturnUri(this string val, int port, bool ssl = default(bool)) { if (string.IsNullOrEmpty(val)) { throw new ArgumentNullException(val); } try { UriBuilder uri; if (val.StartsWith("http://", StringComparison.Ordinal)) { var split = val.Split('/'); uri = split.Length >= 4 ? new UriBuilder(Uri.UriSchemeHttp, split[2], port, "/" + split[3]) : new UriBuilder(new Uri($"{val}:{port}")); } else if (val.StartsWith("https://", StringComparison.Ordinal)) { var split = val.Split('/'); uri = split.Length >= 4 ? new UriBuilder(Uri.UriSchemeHttps, split[2], port, "/" + split[3]) : new UriBuilder(Uri.UriSchemeHttps, split[2], port); } else if(ssl) { uri = new UriBuilder(Uri.UriSchemeHttps, val, port); } else { uri = new UriBuilder(Uri.UriSchemeHttp, val, port); } return uri.Uri; } catch (Exception exception) { throw new Exception(exception.Message, exception); } }
public static Uri ReturnUriWithSubDir(this string val, int port, bool ssl, string subDir) { var uriBuilder = new UriBuilder(val); if (ssl) { uriBuilder.Scheme = Uri.UriSchemeHttps; } if (!string.IsNullOrEmpty(subDir)) { uriBuilder.Path = subDir; } uriBuilder.Port = port; return uriBuilder.Uri; }
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。