duheng
2024-05-29 b4189107397fb4e2da2bd9343d0eb85d44918932
WaterPredict/IStation.ChEr.Application.WaterPredict/02-predict/ConnectHelper.cs
@@ -121,5 +121,42 @@
            //   error = null;
            return ret.Data;
        }
        public static List<SSAData> GetByPumpOpenState(DateTime starttime, DateTime endtime)
        {
            // string apiServiceUrl = System.Configuration.ConfigurationManager.AppSettings["ApiServiceUrl"];
            string apiServiceUrl = "http://192.168.21.14:86/";
            string url = string.Format(@"{0}/PumpRun/GetPumpOpenState?startday={1}&endday={2}", apiServiceUrl, starttime, endtime);
            string Accept = "application/json";
            //创建Web访问对象
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
            myRequest.Method = "GET";
            //myRequest.Accept = "application/json";
            // myRequest.ContentType = "application/json";  // //Content-Type: application/x-www-form-urlencoded
            myRequest.AutomaticDecompression = DecompressionMethods.GZip;
            myRequest.Accept = Accept;
            //myRequest.ContentType = ContentType;
            myRequest.ContentType = "application/json; charset=UTF-8";
            //myRequest.ContentLength = buf.Length;
            myRequest.MaximumAutomaticRedirections = 1;
            myRequest.AllowAutoRedirect = true;
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            //通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            //string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
            string returnData = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
            if (string.IsNullOrEmpty(returnData))
            {
                myResponse.Close();
                //       error = "利用StreamReader就可以从响应内容从头读到尾";
                return null;
            }
            var ret = Yw.JsonHelper.Json2Object<IStation.Dto.ApiResult<List<SSAData>>>(returnData);
            reader.Close();
            myResponse.Close();
            //   error = null;
            return ret.Data;
        }
    }
}