NameValuePairの単純な名前と値のペアのノードタイプ

///  <要約> 
        /// 要求されたテキストパラメータの組立通常のPOSTリクエスト
         ///  </要約> 
        ///  <PARAM NAME = "パラメータ"> キー・リクエストパラメータ辞書は、値を形成する</ param>の
        ///  <リターン> URLエンコードされたデータ要求</戻り> 
        静的 パブリック 文字列 BuildQuery(IDictionaryを< 文字列文字列 > パラメータ)
        { 
            StringBuilderのPOSTDATA = 新しい新;のStringBuilder()
             BOOL hasParam = falseに; 

            のIEnumerator <KeyValuePair < 文字列文字列DEM = >> parameters.GetEnumerator();
             一方(dem.MoveNext())
            { 
                文字列名= dem.Current.Key、
                 文字列値は、= dem.Current.Value;
                 // 無視パラメータ名またはパラメータがnullである
                場合(!文字列!.IsNullOrEmpty(名)&& ストリング.IsNullOrEmpty(値))
                { 
                    IF (hasParam)
                    { 
                        postData.Append(" " ); 
                    }
 
                    postData.Append(名);
                    postData.Append(" = "); 
                    postData.Append(Uri.EscapeDataString(値))。
                    hasParam = ; 
                } 
            } 

            を返す)(postData.ToStringします。
        }
コードの表示

Uri.EscapeDataString

 

publicvoid UrlEncodeTest()
{ 
    文字列のURL = " C ++のC#" ; 
    Console.WriteLineを(HttpUtility.UrlEncode(URL)); // C%2B%2Bの+のCの%23 
    Console.WriteLineを(HttpUtility.UrlPathEncode(URL))。// C ++%20Cの#1 
    Console.WriteLineを(Uri.EscapeUriString(URL)); // C ++%20Cの#1 
    Console.WriteLineを(Uri.EscapeDataString(URL)); // C%2B%2B%20cは%23 
}
コードの表示

 

おすすめ

転載: www.cnblogs.com/hofmann/p/11534200.html