static String Send(String apiName, String apiVersion, Dictionary<String, String> dict)
{
HttpWebRequest request = WebRequest.Create(URL) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json";
// 设置请求参数
dict.Add("_api_access_key", AK);
dict.Add("_api_name", apiName);
dict.Add("_api_version", apiVersion);
// 对参数进行字典序排序
List<KeyValuePair<string, string>> lst = new List<KeyValuePair<string, string>>(dict);
lst.Sort(delegate (KeyValuePair<string, string> source, KeyValuePair<string, string> target)
{
return source.Key.CompareTo(target.Key);
});
StringBuilder signBuilder = new StringBuilder();
StringBuilder paramBuilder = new StringBuilder();
// 拼写请求字串
foreach (KeyValuePair<string, string> item in lst)
{
string key = item.Key;
string value = item.Value;
// 签名字串
signBuilder.Append("&").Append(key).Append("=").Append(value);
//value = Server
if (HEADERS.Contains(key))
{
request.Headers[key] = value;
}
else
{
paramBuilder.Append("&").Append(key).Append("=").Append(value);
}
}
if(paramBuilder.Length>1) paramBuilder.Remove(0, 1);
signBuilder.Remove(0, 1);
string signStr = signBuilder.ToString();
}