Пример #1
0
        public static RequestInformation Create(HttpRequest request)
        {
            var info = new RequestInformation();
            info.Method = request.HttpMethod;
            info.Url = request.RawUrl;
            info.Headers = request.Headers;

            var cookies = new NameValueCollection();
            CookieCollection cookieCollection = RequestHelper.GetRequestCookies(request);
            foreach (Cookie cookie in cookieCollection)
            {
                cookies.Add(cookie.Name, cookie.Value);
            }
            info.Cookies = cookies;

            Stream stream = request.GetBufferedInputStream();
            using (var reader = new StreamReader(stream))
            {
                string body = reader.ReadToEnd();
                info.BodyContent = body;
                info.BodyLength = body.Length;
            }

            info.SecureConnection = request.IsSecureConnection;

            var cs = request.ClientCertificate;
            info.ClientCertificatePresent = cs.IsPresent;
            if (cs.IsPresent)
            {
                info.ClientCertificate = request.ClientCertificate;
            }

            return info;
        }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            RequestInformation info = RequestInformation.Create(context.Request);

            string echoJson = info.SerializeToJson();

            // Compute MD5 hash to clients can verify the received data.
            MD5 md5 = MD5.Create();

            byte[] bytes       = Encoding.ASCII.GetBytes(echoJson);
            var    hash        = md5.ComputeHash(bytes);
            string encodedHash = Convert.ToBase64String(hash);

            context.Response.Headers.Add("Content-MD5", encodedHash);

            RequestInformation newEcho = RequestInformation.DeSerializeFromJson(echoJson);

            context.Response.ContentType = "text/plain"; //"application/json";
            context.Response.Write(echoJson);
        }
Пример #3
0
        public static RequestInformation Create(HttpRequest request)
        {
            var info = new RequestInformation();

            info.Method  = request.HttpMethod;
            info.Url     = request.RawUrl;
            info.Headers = request.Headers;

            var cookies = new NameValueCollection();
            CookieCollection cookieCollection = RequestHelper.GetRequestCookies(request);

            foreach (Cookie cookie in cookieCollection)
            {
                cookies.Add(cookie.Name, cookie.Value);
            }
            info.Cookies = cookies;

            Stream stream = request.GetBufferedInputStream();

            using (var reader = new StreamReader(stream))
            {
                string body = reader.ReadToEnd();
                info.BodyContent = body;
                info.BodyLength  = body.Length;
            }

            info.SecureConnection = request.IsSecureConnection;

            var cs = request.ClientCertificate;

            info.ClientCertificatePresent = cs.IsPresent;
            if (cs.IsPresent)
            {
                info.ClientCertificate = request.ClientCertificate;
            }

            return(info);
        }