コード例 #1
0
        public HTTPHostTest()
            : base(LogicOf <Nothing> .New((x) =>
        {
            var ep   = EndPoint.NewFreeLocalEndPointSpecifyingPort(80);
            var host = HTTPHost.New(ep, (req) =>
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("<HTML><BODY>");
                var lines = HTTPHost.DumpHTTPRequest(req);
                foreach (var eachline in lines)
                {
                    sb.AppendLine(eachline + "<BR>");
                }
                sb.AppendLine("</BODY></HTML>");

                return(sb.ToString());
            }, "test/");
            host.Initialize();
            host.Start();

            string uri = "http://" + ep.IPAddress + ":" + ep.Port + "/test/";

            //Console.ReadLine();

            //now hit it with some requests
            using (var client = new HttpClient())
            {
                var getdat = HTTPClient.Get(client, uri);
                HTTPClient.Delete(client, uri);
                var postdat = HTTPClient.Post(client, new StringContent("yo"), uri);
                var putdat  = HTTPClient.Put(client, new StringContent("yo"), uri);
            }
        }))
        {
        }
コード例 #2
0
ファイル: HTTPSHostTest.cs プロジェクト: Piirtaa/Decoratid
        public HTTPSHostTest()
            : base(LogicOf <Nothing> .New((x) =>
        {
            var ep = EndPoint.NewFreeLocalEndPointSpecifyingPort(80);

            var host = HTTPSHost.New(ep,
                                     (req) =>
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("<HTML><BODY>");
                var lines = HTTPSHost.DumpHTTPRequest(req);
                foreach (var eachline in lines)
                {
                    sb.AppendLine(eachline + "<BR>");
                }
                sb.AppendLine("</BODY></HTML>");

                return(sb.ToString());
            }, "test/");

            using (host)
            {
                host.Initialize();
                host.Start();

                string uri = "https://" + ep.IPAddress + ":" + ep.Port;

                //Console.ReadLine();

                ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

                //using (WebClient webClient = new WebClient())
                //{
                //    var stream = webClient.OpenRead(uri);
                //    using (StreamReader sr = new StreamReader(stream))
                //    {
                //        var page = sr.ReadToEnd();
                //    }
                //}

                //now hit it with some requests
                using (var client = new HttpClient())
                {
                    var getdat = HTTPClient.Get(client, uri);
                    HTTPClient.Delete(client, uri);
                    var postdat = HTTPClient.Post(client, new StringContent("yo"), uri);
                    var putdat  = HTTPClient.Put(client, new StringContent("yo"), uri);
                }
            }
        }))
        {
        }