Beispiel #1
0
        public static string ParamToString(AlarmModel alarmParams)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("{0}={1}", "FilteredDeviceType", alarmParams.FilteredDeviceType);
            buffer.AppendFormat("&{0}={1}", "FilteredStatus", alarmParams.FilteredStatus);
            buffer.AppendFormat("&{0}={1}", "FilteredLevel", alarmParams.FilteredLevel);
            buffer.AppendFormat("&{0}={1}", "FilteredStartTime", alarmParams.FilteredStartTime);
            buffer.AppendFormat("&{0}={1}", "FilteredEndTime", alarmParams.FilteredEndTime);
            buffer.AppendFormat("&{0}={1}", "OrderedDevice", alarmParams.OrderedDevice);
            buffer.AppendFormat("&{0}={1}", "OrderedLevel", alarmParams.OrderedLevel);
            buffer.AppendFormat("&{0}={1}", "OrderedTime", alarmParams.OrderedTime);
            return(buffer.ToString());
        }
Beispiel #2
0
        public static string HttpPost(string url, HttpContext context, AlarmModel alarmParams)
        {
            var request  = context.Request;
            var response = context.Response;

            try
            {
                var alarmUrl     = context.Server.HtmlEncode(url);
                var proxyRequest = (HttpWebRequest)WebRequest.Create(alarmUrl);
                proxyRequest.Method      = "Post";
                proxyRequest.UserAgent   = request.UserAgent;
                proxyRequest.ContentType = "application/x-www-form-urlencoded";
                var noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                proxyRequest.CachePolicy = noCachePolicy;

                string   buffer   = ParamToString(alarmParams);
                Encoding encode   = Encoding.GetEncoding("utf-8");
                byte[]   tempdata = encode.GetBytes(buffer);
                proxyRequest.ContentLength = tempdata.Length;
                Stream stream = proxyRequest.GetRequestStream();
                stream.Write(tempdata, 0, tempdata.Length);
                stream.Close();

                // 构造响应对象
                response.ContentType = "text/html";
                //发出代理请求,并获取响应
                using (HttpWebResponse proxyResponse = proxyRequest.GetResponse() as HttpWebResponse)
                {
                    response.StatusCode = (int)proxyResponse.StatusCode;
                    string Result;
                    using (Stream receiveStream = proxyResponse.GetResponseStream())
                    {
                        Encoding     Encode     = Encoding.GetEncoding("utf-8");
                        StreamReader readStream = new StreamReader(receiveStream, Encode);
                        Result = readStream.ReadToEnd();
                    }
                    return(Result);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }