public static String urlCharactersEncoding(String str) { if (QSStringUtil.isEmpty(str)) { return(""); } StringBuilder buffer = new StringBuilder(); try { for (int i = 0; i < str.Length; i++) { String temp = str.Substring(i, 1); if (' '.Equals(temp)) { buffer.Append("%20"); } else if ('/'.Equals(temp) || '&'.Equals(temp) || '='.Equals(temp) || ':'.Equals(temp)) { buffer.Append(temp); } else { buffer.Append(HttpUtility.UrlEncode(temp, Encoding.GetEncoding(QSConstant.ENCODING_UTF8))); } } return(buffer.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } return(""); }
/** * Chinese characters transform * * @param str * @return */ public static string chineseCharactersEncoding(string str) { if (QSStringUtil.isEmpty(str)) { return(""); } StringBuilder buffer = new StringBuilder(); try { for (int i = 0; i < str.Length; i++) { string temp = str.Substring(i, 1); if (Encoding.UTF8.GetBytes(temp).Length > 1) { buffer.Append(HttpUtility.UrlEncode(temp, Encoding.GetEncoding(QSConstant.ENCODING_UTF8))); } else { buffer.Append(temp); } } return(buffer.ToString()); } catch (Exception e) { System.Console.WriteLine(e.Message); } return(null); }
private static void setParameterToDictionary(MethodInfo m, object source, Dictionary <object, object> retParametersDictionary, string paramKey) { object[] invokeParams = null; object objValue = m.Invoke(source, invokeParams); if (objValue != null) { Type Ts = objValue.GetType(); if (Ts.Equals(typeof(int)) || Ts.Equals(typeof(double)) || Ts.Equals(typeof(Boolean)) || Ts.Equals(typeof(bool)) || Ts.Equals(typeof(long)) || Ts.Equals(typeof(float))) { retParametersDictionary.Add(paramKey, objValue.ToString()); } else if (Ts.Equals(typeof(string)) || Ts.Equals(typeof(string))) { retParametersDictionary.Add(paramKey, QSStringUtil.chineseCharactersEncoding(objValue + "")); } else { retParametersDictionary.Add(paramKey, objValue); } } }
public static string generateQSURL(Dictionary <object, object> parameters, string requestUrl) { parameters = QSParamInvokeUtil.serializeParams(parameters); StringBuilder sbStringToSign = new StringBuilder(); string[] sortedKeys = new string[200]; int i = 0; foreach (var key in parameters.Keys) { sortedKeys[i] = key.ToString(); i++; } //Array.Sort(sortedKeys); int j; int count = 0; try { for (j = 0; j < i; j++) { string key = sortedKeys[j]; if (count != 0) { sbStringToSign.Append("&"); } sbStringToSign .Append(QSStringUtil.percentEncode(key, QSConstant.ENCODING_UTF8)) .Append("=") .Append(QSStringUtil.percentEncode(parameters[key].ToString(), QSConstant.ENCODING_UTF8)); count++; } } catch (Exception e) { logger.Error(e.Message); System.Console.WriteLine(e.Message); } if (sbStringToSign.Length > 0) { if (requestUrl.IndexOf("?") > 0) { return(requestUrl + "&" + sbStringToSign.ToString()); } else { return(requestUrl + "?" + sbStringToSign.ToString()); } } return(requestUrl); }