zoukankan      html  css  js  c++  java
  • Uri.AbsoluteUri 与 Uri.ToString() 的区别

    UriBuilder builder = new UriBuilder("http://somehost/somepath");

    builder.Query = "somekey=" + HttpUtility.UrlEncode("some+value");

    Uri someUri = builder.Uri;

    Response.Write("" + someUri.AbsoluteUri + "");

    Response.Write("" + someUri.ToString() + "");

    显示的结果如下:

    http://somehost/somepath?somekey=some%2bvalue

    http://somehost/somepath?somekey=some+value

    可以看出 AbsoluteUri 是经过编码的,如果访问这个网址,再取 somekey 的值,结果为“some+value”,符合原值。

    而 ToString() 是取原值,如果访问这个网址,再取 somekey 的值时,结果为“some value”,与原值不符。

    也就是说:如果要在浏览器中传送这个 Uri,则使用 AbsoluteUri;如果要获得未编码的 Uri,则使用 ToString()。

  • 相关阅读:
    Two Sum II
    Subarray Sum
    Intersection of Two Arrays
    Reorder List
    Convert Sorted List to Binary Search Tree
    Remove Duplicates from Sorted List II
    Partition List
    Linked List Cycle II
    Sort List
    struts2结果跳转和参数获取
  • 原文地址:https://www.cnblogs.com/slu182/p/4613248.html
Copyright © 2011-2022 走看看