using System; using System.Collections.Generic; using System.Text; using System.IO; namespace FastReport.Cloud { /// /// Static class that contains HTTP utilities. /// internal static class HttpUtils { #region Public Methods /// /// Encodes the URL string. /// /// The URL string. /// The encoded URL string. public static string UrlEncode(string str) { StringBuilder sb = new StringBuilder(); StringReader reader = new StringReader(str); int charCode = reader.Read(); while (charCode != -1) { if (((charCode >= 48) && (charCode <= 57)) || ((charCode >= 65) && (charCode <= 90)) || ((charCode >= 97) && (charCode <= 122))) { sb.Append((char)charCode); } else if (charCode == 32) { sb.Append("+"); } else { sb.AppendFormat("%{0:x2}", charCode); } charCode = reader.Read(); } return sb.ToString(); } /// /// Encodes the dictionary with URL parameters. /// /// The dictionary with parameters. /// The encoded string. public static string UrlDataEncode(Dictionary data) { StringBuilder sb = new StringBuilder(); string format = "{0}={1}"; bool first = true; foreach (KeyValuePair pair in data) { sb.AppendFormat(format, pair.Key, pair.Value); if (first) { format = "&{0}={1}"; first = false; } } return sb.ToString(); } /// /// Decodes the URL string. /// /// The URL string. /// The decoded URL string. public static string UrlDecode(string str) { return Uri.UnescapeDataString(str); } #endregion // Public Methods } }