Example #1
0
        public override Patient_DTO GetPatient(string patientId)
        {
            try
            {
                var patientUrl = Config.HttpConfigModel.PatientUrl;
                CommunicationHelper.RecordTrace("GetPatient", $"开始获取病人{patientId}的信息");
                Patient_DTO patient = null;
                if (_helper == null)
                {
                    return(null);
                }
                CommunicationHelper.RecordTrace("GetPatient", $"获取病人信息地址为{patientUrl}");
                string url = string.Empty;

                if (patientUrl.EndsWith("=") || patientUrl.EndsWith("/"))
                {
                    url = patientUrl + patientId;
                }
                else
                {
                    url = patientUrl + "/" + patientId;
                }

                var finalUrl = AddToken(url);

                _helper.NeedUrlDecode = NeedUrlDecode;
                patient = _helper.HttpGetData <Patient_DTO>(finalUrl);
                return(patient);
            }
            catch (KRException ex)
            {
                throw new Exception(ex.Msg);
            }
        }
        public string HttpGetData(string url, HttpItem pitem = null)
        {
            try
            {
                var httpItem = pitem ?? new HttpItem()
                {
                    URL = url
                };

                var result     = _engine.GetHtml(httpItem);
                var strContent = result.Html;
                CommunicationHelper.RecordTrace("HttpGetData", "返回的数据" + result.Html);
                return(strContent);
                //string retString = string.Empty;
                //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                //request.Method = "GET";
                //request.ContentType = "Content-Type = application/json";
                //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                //Stream myResponseStream = response.GetResponseStream();
                //StreamReader myStreamReader = new StreamReader(myResponseStream, encoder);
                //retString = myStreamReader.ReadToEnd();
                //myStreamReader.Close();
                //myResponseStream.Close();
                //return DecodeResponseStr(retString);
            }
            catch (Exception ex)
            {
                ClientHelper.TraceException("HttpPostData:Get", "Get数据失败", ex.Message);
                return(string.Empty);
            }
        }
        public string HttpPostData(string url, object paramter, HttpItem pitem = null)
        {
            try
            {
                if (paramter == null)
                {
                    CommunicationHelper.TraceException("HttppostData", "null parameter", "parameter obj is null");
                }

                string contentType = "application/json";

                if (paramter is string || paramter.GetType().IsValueType)
                {
                    contentType = "application/x-www-form-urlencoded";
                }

                var postStr = CommunicationHelper.SerializeObjToJsonStr(paramter);
                if (pitem == null)
                {
                    pitem = new HttpItem()
                    {
                        Method      = "Post",
                        Postdata    = postStr,
                        ContentType = "application/x-www-form-urlencoded",
                        Encoding    = Encoding.UTF8,
                        URL         = url
                    };
                }
                else
                {
                    pitem.Method   = "Post";
                    pitem.Postdata = postStr;
                    //pitem.ContentType = contentType;
                    pitem.URL = url;
                }

                var result = _engine.GetHtml(pitem);
                CommunicationHelper.RecordTrace("HttpPostData", "返回结果:" + result.Html);
                return(result.Html);

                //var client = new KRWebClient { Timeout = Timeout };
                //NameValueCollection param = new NameValueCollection();
                ////client.Headers.Add("Content-Type", "application/json");
                //param.Add("type", type);
                //param.Add("content", jsonStr);
                //var content = client.UploadValues(url, param);
                //var strContent = Encoding.UTF8.GetString(content);
                //return strContent;
                //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                //request.Method = "Post";
                //request.ContentType = "application/json";
                //request.ContentLength = _encoding.GetByteCount(jsonStr);
                //Stream myRequestStream = request.GetRequestStream();
                //StreamWriter myStreamWriter = new StreamWriter(myRequestStream);
                //myStreamWriter.Write(jsonStr);
                //myStreamWriter.Close();

                //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                //Stream myResponseStream = response.GetResponseStream();
                //StreamReader myStreamReader = new StreamReader(myResponseStream);
                //retString = myStreamReader.ReadToEnd();
                //myStreamReader.Close();
                //myResponseStream.Close();
            }
            catch (Exception ex)
            {
                ClientHelper.TraceException("HttpPostData:Post", "Post数据失败", ex.Message);
                return(string.Empty);
            }

            //return HttpUtility.UrlDecode(retString);
        }