什么是Uri.ToString()和Uri.AbsoluteUri之间的区别?区别、Uri、ToString、AbsoluteUri

由网友(晴栀)分享简介:作为注释到Azure的问题,就在刚才,@smarx指出As a comment to an Azure question just now, @smarx noted我认为这是一般好做blob.Uri.AbsoluteUri比blob.Uri.ToString()。I think it's generally be...

作为注释到Azure的问题,就在刚才,@smarx指出

As a comment to an Azure question just now, @smarx noted

我认为这是一般好做blob.Uri.AbsoluteUri比   blob.Uri.ToString()。

I think it's generally better to do blob.Uri.AbsoluteUri than blob.Uri.ToString().

有没有道理呢?该文档 Uri.AbsoluteUri 指出,它获取绝对URI, Uri.ToString()获取规范的字符串重新presentation指定实例。

Is there a reason for this? The documentation for Uri.AbsoluteUri notes that it "Gets the absolute URI", Uri.ToString() "Gets a canonical string representation for the specified instance."

推荐答案

鉴于例如:

UriBuilder builder = new UriBuilder("http://somehost/somepath");
builder.Query = "somekey=" + HttpUtility.UrlEncode("some+value");
Uri someUri = builder.Uri;

在这种情况下, Uri.ToString()将返回一个人类可读的网址:http://somehost/somepath?somekey=some+value

In this case, Uri.ToString() will return a human-readable URL: http://somehost/somepath?somekey=some+value

Uri.AbsoluteUri ,另一方面将返回EN codeD形式HttpUtility.UrlEn code还给了: HTTP ://,某/ somepath somekey =某些%2bvalue

Uri.AbsoluteUri on the other hand will return the encoded form as HttpUtility.UrlEncode returned it: http://somehost/somepath?somekey=some%2bvalue

阅读全文

相关推荐

最新文章