コード例 #1
0
ファイル: OrderManager.cs プロジェクト: radtek/Convenience
        public GetOrdersResponse Gets(GetOrdersCondition condition)
        {
            string mid = condition.memberId;

            if (string.IsNullOrWhiteSpace(mid))
            {
                mid = DefaultMemberId;
            }

            var password = GetPassword(mid);
            var datetime = DateTime.Now;
            var request  = new GetOrdersRequest
            {
                dataMap = condition,
                sign    = BuildSign(condition, datetime, password),
                reqTime = datetime.ToString(DateTimeFormat)
            };

            var jSetting = new JsonSerializerSettings();

            jSetting.NullValueHandling = NullValueHandling.Ignore;
            var content = JsonConvert.SerializeObject(request, jSetting);

            _log.Debug("Post data:" + content);
            var config = new CommonConfig(null);

            var req = (HttpWebRequest)WebRequest.Create(config.JavaOrder_Uri + "queryOrders");

            req.Method      = "POST";
            req.ContentType = "Application/Json";
            req.Credentials = CredentialCache.DefaultCredentials;
            req.Timeout     = 300000;
            // 如果服务器返回错误,他还会继续再去请求,不会使用之前的错误数据,做返回数据
            //req.ServicePoint.Expect100Continue = false;
            WriteRequestData(req, content);
            var response = req.GetResponse();

            if (response == null)
            {
                throw new Exception("请求失败!");
            }
            var stream = response.GetResponseStream();

            if (stream == null)
            {
                throw new Exception("请求Stream为空!");
            }
            var sr     = new StreamReader(stream, Encoding.UTF8);
            var retXml = sr.ReadToEnd();

            sr.Close();
            _log.Debug(retXml);
            var obj = JsonConvert.DeserializeObject <GetOrdersResponse>(retXml);

            if (obj.respCode != "0")
            {
                throw new ApplicationException(obj.respMsg);
            }
            return(obj);
        }
コード例 #2
0
ファイル: OrderManager.cs プロジェクト: radtek/Convenience
        public ResponseInfo <GetOrdersDatamap> Gets(GetOrdersCondition condition)
        {
            var config   = new ApiSetting(null);
            var response = SecurityHttpClient.Post <GetOrdersCondition, GetOrdersDatamap>(config.JavaOrder_Uri + "queryOrders", condition);

            if (response.respCode != "0")
            {
                throw new ApplicationException(response.respMsg);
            }
            return(response);
        }