Ejemplo n.º 1
0
        /// <summary>
        /// 提交数据到服务器
        /// </summary>
        /// <param name="method">方法名称</param>
        /// <param name="parames">参数</param>
        /// <param name="files">文件</param>
        /// <param name="fileKey"></param>
        /// <returns></returns>
        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);
        }
Ejemplo 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);
        }