Esempio n. 1
0
        public string post(string method, Dictionary <string, string> parames, Dictionary <string, object> files, string fileKey)
        {
            Dictionary <string, string> completeParam = buildCompleteParams(method, parames);
            String         paramStr = buildParamStr(completeParam);
            HttpWebRequest request;

            if (files == null || files.Count == 0)
            {
                request           = WebRequest.Create(apiEntry + "?" + paramStr) as HttpWebRequest;
                request.Method    = "POST";
                request.UserAgent = DefaultUserAgent;
            }
            else
            {
                request = KDTUtil.MultipartFormDataPost(apiEntry + "?" + paramStr, DefaultUserAgent, files, fileKey);
            }

            HttpWebResponse result    = request.GetResponse() as HttpWebResponse;
            StreamReader    sr        = new StreamReader(result.GetResponseStream(), Encoding.Default);
            string          strResult = sr.ReadToEnd();

            sr.Close();
            Console.WriteLine(strResult);
            return(strResult);
        }
Esempio n. 2
0
        Dictionary <string, string> buildCompleteParams(string method, Dictionary <string, string> parames)
        {
            Dictionary <String, String> commonParams = getCommonParams(method);

            foreach (var key in parames.Keys)
            {
                if (commonParams.ContainsKey(key))
                {
                    throw new Exception("参数名冲突");
                }

                commonParams.Add(key, parames[key]);
            }
            commonParams.Add(KDTUtil.SIGN_KEY, KDTUtil.sign(appSecret, commonParams, method));
            return(commonParams);
        }