/// <summary> /// URL编码 /// </summary> /// <param name="value">The value to Url encode</param> /// <returns>Returns a Url encoded string</returns> public string UrlEncode(string value) { StringBuilder result = new StringBuilder(); string unreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~"; foreach (char symbol in value) { if (unreservedChars.IndexOf(symbol) != -1) { result.Append(symbol); } else { result.Append('%' + String.Format("{0:X2}", (int)symbol)); } } return result.ToString(); }