What's the difference between Uri.ToString() and Uri.AbsoluteUri?

前端 未结 5 917
情书的邮戳
情书的邮戳 2020-12-14 13:43

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

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

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 14:34

    Given for example:

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

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

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

提交回复
热议问题