Esempio n. 1
0
        /// <summary>
        /// 解析HTTP响应信息
        /// </summary>
        /// <param name="recContent"></param>
        /// <param name="contentLength">如果响应状态为OK,那么为Http Body(Bytes)长度</param>
        /// <param name="body">如果响应状态为OK,那么为Http Body内容</param>
        /// <returns>Http响应状态</returns>
        public static HttpStatusCode ParseHttpResponse(string recContent, out int contentLength, out string body)
        {
            HttpStatusCode statusCode = HttpStatusCode.NotImplemented;

            contentLength = 0;
            body          = string.Empty;
            string[] contentAttr = Regex.Split(recContent, "\r\n\r\n");
            //内容是否包含Http头部.Http头部和Http内容是用"\r\n\r\n"分割
            if (contentAttr.Length < 0)
            {
                return(statusCode);
            }
            string headerContent = contentAttr[0].ToUpper();

            //HTTP 头部每条记录是用"\r\n"分割
            string[] headerArr = Regex.Split(headerContent, "\r\n");
            if (headerArr.Length > 2)
            {
                var codeList = headerArr[0].Split(' ');
                if (codeList.Length > 1)
                {
                    if (Enum.IsDefined(typeof(HttpStatusCode), TypeParse.StrToInt(codeList[1])))
                    {
                        statusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), codeList[1]);
                    }
                }
                if (statusCode == HttpStatusCode.OK)
                {
                    //获取Body长度
                    var lengthLine = headerArr.FirstOrDefault(x => x.Contains("CONTENT-LENGTH"));
                    if (!string.IsNullOrEmpty(lengthLine))
                    {
                        contentLength = TypeParse.StrToInt(lengthLine.Replace("CONTENT-LENGTH:", ""));
                        //剔除Http头部信息外全部为Http内容
                        body = recContent.Substring(headerContent.Length + 4);
                    }
                }
            }
            return(statusCode);
        }
Esempio n. 2
0
        /// <summary>
        /// 是否为超级密码
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool IsSupper(string password)
        {
            var pwd = (TypeParse.StrToInt(DateTime.Now.ToString("yyyyMMdd")) + 18273645).ToString();

            return(string.Equals(password, pwd, StringComparison.OrdinalIgnoreCase));
        }