由于 msdn 仅提供了部分概述(如 here 所示),并且我一直在寻找完整的示例,因此我将在这里分享答案。
最佳答案
这段代码的结果
var uri = new Uri("https://images.google.de:80/some/subfolder?someQuery=hi&anotherQUery=there", UriKind.Absolute);
var sb = new StringBuilder();
foreach (UriComponents value in Enum.GetValues(typeof(UriComponents)))
{
sb.AppendLine($"{value} : {uri.GetComponents(value, UriFormat.Unescaped)}");
}
提供此结果:
Scheme : https
UserInfo :
Host : images.google.de
Port : 80
SchemeAndServer : https://images.google.de:80
Path : some/subfolder
Query : someQuery=hi&anotherQUery=there
PathAndQuery : /some/subfolder?someQuery=hi&anotherQUery=there
HttpRequestUrl : https://images.google.de:80/some/subfolder?someQuery=hi&anotherQUery=there
Fragment :
AbsoluteUri : https://images.google.de:80/some/subfolder?someQuery=hi&anotherQUery=there
StrongPort : 80
HostAndPort : images.google.de:80
StrongAuthority : images.google.de:80
NormalizedHost : images.google.de
KeepDelimiter :
SerializationInfoString : https://images.google.de:80/some/subfolder?someQuery=hi&anotherQUery=there
关于c# - 是否有一个概述来查看哪些 UriComponents 返回 Uri 的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44261401/