/// <Summary> /// assembly ordinary post request for the requested text parameter /// </ Summary> /// <param name = "Parameters"> Key-request parameter dictionary form the Value </ param> /// <returns> requested data encoded URL </ Returns> static public String BuildQuery (the IDictionary < String , String > Parameters) { the StringBuilder postData = new new the StringBuilder (); BOOL hasParam = to false ; the IEnumerator <KeyValuePair < String , StringDEM = >> parameters.GetEnumerator (); the while (dem.MoveNext ()) { String name = dem.Current.Key; String value = dem.Current.Value; // Ignore parameter name or parameter is null if (! String .IsNullOrEmpty (name) &&! String .IsNullOrEmpty (value)) { IF (hasParam) { postData.Append ( " & " ); } postData.Append (name); postData.Append ( " = "); postData.Append(Uri.EscapeDataString(value)); hasParam = true; } } return postData.ToString(); }
Uri.EscapeDataString
publicvoid UrlEncodeTest() { string url ="C++ C#"; Console.WriteLine(HttpUtility.UrlEncode(url));//C%2b%2b+C%23 Console.WriteLine(HttpUtility.UrlPathEncode(url));//C++%20C# Console.WriteLine(Uri.EscapeUriString(url));//C++%20C# Console.WriteLine(Uri.EscapeDataString(url));//C%2B%2B%20C%23 }