Пример #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);
        }
Пример #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);
        }