Ejemplo n.º 1
0
        /// <summary>
        /// 获取请求的数据
        /// </summary>
        /// <param name="strUrl">请求地址</param>
        /// <param name="requestMode">请求方式</param>
        /// <param name="parameters">参数</param>
        /// <param name="requestCoding">请求编码</param>
        /// <param name="responseCoding">响应编码</param>
        /// <param name="timeout">请求超时时间(毫秒)</param>
        /// <returns>返回:请求成功响应信息,失败返回null</returns>
        public string GetResponseString(string strUrl, ERequestMode requestMode, Dictionary <string, string> parameters, Encoding requestCoding, Encoding responseCoding, out string error, int timeout = 300)
        {
            error = "";
            string         url        = VerifyUrl(strUrl);
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));

            HttpWebResponse webResponse = null;

            switch (requestMode)
            {
            case ERequestMode.Get:
                webResponse = GetRequest(webRequest, out error, timeout);
                break;

            case ERequestMode.Post:
                webResponse = PostRequest(webRequest, parameters, requestCoding, out error, timeout);
                break;
            }

            if (webResponse != null && webResponse.StatusCode == HttpStatusCode.OK)
            {
                using (Stream newStream = webResponse.GetResponseStream()) {
                    if (newStream != null)
                    {
                        using (StreamReader reader = new StreamReader(newStream, responseCoding)) {
                            string result = reader.ReadToEnd();
                            return(result);
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public ParamUtm(HttpRequest request) : base(request)
        {
            // parse style
            if (request["style"] == null)
            {
                throw new Exception("Param: style is missing");
            }
            string modeStr = request["style"].ToLower();

            if (modeStr.StartsWith("bt"))
            {
                mode = ERequestMode.SingleTile;
            }
            else if (modeStr.StartsWith("dt"))
            {
                mode = ERequestMode.MultiTiles;
            }
            else if (modeStr.StartsWith("so"))
            {
                mode = ERequestMode.OriginList;
            }
            else if (modeStr.StartsWith("ts"))
            {
                mode = ERequestMode.TimeSeriesList;
            }
            else
            {
                throw new Exception("Param: unknown style: " + modeStr + " request:" + request.Url.Query);
            }

            // parse layerType
            if (request["LayerType"] != null)
            {
                string layerTypeString = request["LayerType"].ToLower();
                if (layerTypeString == "fmap")
                {
                    layerType = ELayerType.FMap;
                }
                else if (layerTypeString == "mapnik")
                {
                    layerType = ELayerType.Mapnik;
                }
                else
                {
                    throw new Exception("Param: unknown LayerType: " + layerTypeString + " request:" + request.Url.Query);
                }
            }

            ////////////// parse common params used by all modes //////////////
            // required
            zone = GetIntParam("utmz1");
            res  = GetDoubleParam("res");

            // optional
            if (request["source"] != null)
            {
                originName = request["source"].ToUpper();
            }
            if (request["jcq"] != null)
            {
                jpegQuality = GetIntParam("jcq");
            }

            // optional
            overlay = request["overlay"];
            if (overlay == null)
            {
                overlay = request["composite"];
            }

            ////////////// parse different params for different modes //////////////
            // xn and yn are for SingleTile mode
            if (mode == ERequestMode.SingleTile)
            {
                tilexy.x     = GetUIntParam("xn");
                xn           = tilexy.x;
                tilexy.y     = GetUIntParam("yn");
                yn           = tilexy.y;
                tilexy.y     = ProjectionUtm.Transform_YnOld_YnNew(tilexy.y, res);
                tilexy.level = ProjectionUtm.ResToLevel(res);
            }

            // x1 y1 x2 y2 are not for single tile request
            if (mode != ERequestMode.SingleTile)
            {
                utmxy1.x   = GetDoubleParam("x1");
                utmxy1.y   = GetDoubleParam("y1");
                utmxy1.res = res;
                utmxy2.x   = GetDoubleParam("x2");
                utmxy2.y   = GetDoubleParam("y2");
                utmxy2.res = res;
                utmxy      = utmxy1;
            }

            date = 0;
            if (request["QFSOURCE_IMAGE_DATE"] != null)
            {
                Int32.TryParse(request["QFSOURCE_IMAGE_DATE"], out date);
            }
        }