Esempio n. 1
0
        private Dictionary <string, string> buildGetRequest(string url)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();
            HttpWebRequest request             = RequestUtility.CreateGetHttpRequest(url);

            request.KeepAlive = true;
            setCustomHeaders(request);

            string strSignData = signData(request);

            //Debug.WriteLine("=================================================");
            //Debug.WriteLine(strSignData);
            //Debug.WriteLine("=================================================");

            request.Headers.Add(PaymaxConfig.SIGN, strSignData);

            WebResponse response = null;

            try
            {
                response = request.GetResponse();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                throw ex;
            }

            if (response == null)
            {
                throw new Exception("返回相应为null.");
            }

            HttpWebResponse httpResponse = response as HttpWebResponse;

            result = verifyData(httpResponse);

            return(result);
        }
Esempio n. 2
0
        private Dictionary <string, string> buildPostRequest(string url, string jsonReqData)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();
            HttpWebRequest request             = RequestUtility.CreatePostHttpRequest(url);

            byte[] data = ToBytes(jsonReqData);
            using (System.IO.Stream stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }
            request.KeepAlive = true;
            setCustomHeaders(request);

            Console.WriteLine("请求的信息:");
            Console.WriteLine(request.Address);
            Console.WriteLine(request.Method);
            Console.WriteLine(jsonReqData);

            string strSignData = signData(request, data);

            Console.WriteLine("请求的签名结果:" + strSignData);

            //Debug 输出信息
            Debug.WriteLine("=================请求的签名结果 start===============================");
            Debug.WriteLine(strSignData);
            Debug.WriteLine("=================请求的签名结果  end===============================");

            request.Headers.Add(PaymaxConfig.SIGN, strSignData);

            WebResponse response = null;
            Stream      stream2  = null;

            try
            {
                response = request.GetResponse();
            }
            catch (WebException we)
            {
                stream2 = we.Response.GetResponseStream();
                StreamReader sr   = new StreamReader(stream2);
                string       body = sr.ReadToEnd();
                Console.WriteLine("响应的body-错误信息:" + body);
                throw we;
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                throw ex;
            }

            if (response == null)
            {
                throw new Exception("返回相应为null.");
            }

            HttpWebResponse httpResponse = response as HttpWebResponse;

            result = verifyData(httpResponse);

            return(result);
        }