当前位置: 首页>>代码示例>>C#>>正文


C# HttpServer.StartServer方法代码示例

本文整理汇总了C#中Microsoft.SPOT.Platform.Tests.HttpServer.StartServer方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.StartServer方法的具体用法?C# HttpServer.StartServer怎么用?C# HttpServer.StartServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.SPOT.Platform.Tests.HttpServer的用法示例。


在下文中一共展示了HttpServer.StartServer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NotSupportExceptionTest

        public MFTestResults NotSupportExceptionTest()
        {
            MFTestResults result = MFTestResults.Pass;
            try
            {
                Log.Comment("WebResponse Test");
                HttpWebRequest wrStr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/");

                HttpServer server = new HttpServer("http", ref result)
                {
                    RequestUri = wrStr.RequestUri,
                    RequestHeaders = wrStr.Headers,
                    ResponseString = "<html><body>WebResponse Test</body></html>"
                };

                server.StartServer();

                WebRequest wr = wrStr;

                WebResponse wresp = wr.GetResponse();

                Log.Comment("Check ResponseUri property");
                if (wresp.ResponseUri.AbsoluteUri != wr.RequestUri.AbsoluteUri)
                {
                    Log.Exception("Expected " + HttpTests.MSUrl + ", but got " + wresp.ResponseUri.AbsoluteUri);
                    result = MFTestResults.Fail;
                }

                Log.Comment("Check ContentType property");
                if (wresp.ContentType != "")
                {
                    Log.Exception("Expected: " + wr.ContentType);
                    result = MFTestResults.Fail;
                }

                Log.Comment("Invoke WebResponse.Close()");
                try
                {
                    wresp.Close();
                }
                catch (System.NotSupportedException e)
                {
                    Log.Exception("Get exception when invoke WebResponse.Close(). " + e.Message.ToString());
                    result = MFTestResults.Fail;
                }
                finally
                {
                    //Stop server
                    server.StopServer();
                }

            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return result;
        }
开发者ID:samunake,项目名称:netmf-interpreter,代码行数:60,代码来源:WebResponseTests.cs

示例2: ValidDefaultTestHTTPStatusCodeHTTP1_1

        public MFTestResults ValidDefaultTestHTTPStatusCodeHTTP1_1()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>ValidDefaultTestHTTPStatusCodeHTTP1_1</body></html>"
            };

            try
            {
                // Setup server
                server.StartServer();

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                Log.Comment("Expect StatusCode - OK");
                if (HttpStatusCode.OK != response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = OK but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }

                Log.Comment("Receive " + response.StatusDescription);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:samunake,项目名称:netmf-interpreter,代码行数:51,代码来源:HttpStatusCodeTests.cs

示例3: ValidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1

        public MFTestResults ValidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1()
        {
            MFTestResults result = MFTestResults.Pass;
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();
                System.Net.WebHeaderCollection wrc = wr.Headers;
                
                // Tests
                Verify(wrc, server.RequestHeaders);
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:39,代码来源:HttpRequestHeaderTests.cs

示例4: InvalidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1_FTP

        public MFTestResults InvalidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1_FTP()
        {
            MFTestResults result = MFTestResults.Pass;
            UriProperties props = new UriProperties("ftp", "//ftp.microsoft.com");
            Uri uri = new Uri(props.OriginalUri);

            Log.Comment("Negative Test case 2:");
            Log.Comment("Create WebRequest with FTP uri");
            try
            {
                HttpWebRequest wrftp = (HttpWebRequest)WebRequest.Create(uri);
            }
            catch (System.NotSupportedException)
            {
                Log.Comment("Create WebRequest with FTP uri - Expected System.NotSupportedException");
            }

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://ftp.microsoft.com");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();

                System.Net.WebHeaderCollection wrc = wr.Headers;

                // Tests
                Verify(wrc, server.RequestHeaders);
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                // Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:54,代码来源:HttpRequestHeaderTests.cs

示例5: TestWebExceptionHTTP1_1_ServerProtocolViolation

        public MFTestResults TestWebExceptionHTTP1_1_ServerProtocolViolation()
        {
            MFTestResults result = MFTestResults.Pass;


            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + HttpServer.s_CurrentPort.ToString() + "/webexception/ServerProtocolViolation.html");  //expect ServerProtocolViolation
            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            wr.Method = "HEAD";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = ""
            };

            try
            {
                // Setup server
                server.StartServer();

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                Log.Comment("Expect ServerProtocolViolation");

                VerifyStream(response, server);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("Exception caught: ", ex);
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:45,代码来源:WebExceptionTests.cs

示例6: TestHTTPStatusCodeHTTP1_1_RequestUriTooLong

        public MFTestResults TestHTTPStatusCodeHTTP1_1_RequestUriTooLong()
        {
            MFTestResults result = MFTestResults.Pass;


            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/local/webpages/mysubdir/index.html");  //expect 414 - RequestUriTooLong
            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            wr.Method = "GET";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>TestHTTPStatusCodeHTTP1_1_RequestUriTooLong</body></html>"
            };

            try
            {
                // Setup server
                server.StartServer();

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                Log.Comment("Expect StatusCode - RequestUriTooLong");
                if ((int)HttpStatusCode.RequestUriTooLong != (int)response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = RequestUriTooLong but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }
                Log.Comment("Receive " + response.StatusDescription);
                response.Close();

            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {

                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:samunake,项目名称:netmf-interpreter,代码行数:52,代码来源:HttpStatusCodeTests.cs

示例7: DefaultTestHTTPStatusCodeHTTP1_1_NotExistUriPath

        public MFTestResults DefaultTestHTTPStatusCodeHTTP1_1_NotExistUriPath()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/webpages/NotExistUriPath.html");      
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>DefaultTestHTTPStatusCodeHTTP1_1_NotExistUriPath</body></html>"
            };

            try
            {
                // Setup server
                server.StartServer();

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                Log.Comment("Expect StatusCode - NotFound  ");
                if (HttpStatusCode.NotFound != response.StatusCode)
                {
                    if ("0" == response.StatusCode.ToString())
                        Log.Exception("Known Issue::Bug 68085 - HttpStatusCode = 0 was returned");
                    else
                        Log.Exception("Expect HttpStatusCode = NotFound but get " + response.StatusCode);
                    result = MFTestResults.Fail;
                }

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:samunake,项目名称:netmf-interpreter,代码行数:51,代码来源:HttpStatusCodeTests.cs

示例8: TestHTTPStatusCodeHTTP1_1_SendChunked_WithTransferEncoding

        public MFTestResults TestHTTPStatusCodeHTTP1_1_SendChunked_WithTransferEncoding()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);
            wr.SendChunked = true;
            wr.TransferEncoding = "Quoted-printable";

            string requestString = "ContentLength: " + wr.ContentLength
            + " ContentType:" + wr.ContentType + " KeepAlive:" + wr.KeepAlive
            + " ProtocolVersion:" + wr.ProtocolVersion + " TransferEncoding:" + wr.TransferEncoding
            + " SendChunked:" + wr.SendChunked + " Expect:" + wr.Expect
            + " Timeout:" + wr.Timeout;

            Log.Comment(requestString);
            
            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>TestHTTPStatusCodeHTTP1_1_SendChunked_WithTransferEncoding</body></html>"
            };

            try
            {
                // Setup server
                server.StartServer();

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                string ResponseString = "Server response: ContentEncoding:" + response.ContentEncoding + " ContentLength: " + response.ContentLength
                        + " ContentType:" + response.ContentType
                        + " ProtocolVersion:" + response.ProtocolVersion
                        + " StatusCode:" + response.StatusCode + " StatusDescription:" + response.StatusDescription;

                Log.Comment(ResponseString);

                Log.Comment("Expect StatusCode - OK");
                if (HttpStatusCode.OK != response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = OK but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }

                Log.Comment("Receive " + response.StatusDescription);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:samunake,项目名称:netmf-interpreter,代码行数:68,代码来源:HttpStatusCodeTests.cs

示例9: InValidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_0_HTTPS

        public MFTestResults InValidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_0_HTTPS()
        {
            MFTestResults result = MFTestResults.Pass;
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("https://"+ Utilities.GetLocalIpAddress() + ":443/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Negative Test case 4:");
            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.0");
            wr.ProtocolVersion = new Version(1, 0);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();
                System.Net.WebHeaderCollection wrc = wr.Headers;

                // Tests
                Verify(wrc, server.RequestHeaders);
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                // Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:40,代码来源:HttpRequestHeaderTests.cs

示例10: InValidDefaultTestGetHTTPResponseHeaderAfterCreateHTTP1_1_ftp1_0

        public MFTestResults InValidDefaultTestGetHTTPResponseHeaderAfterCreateHTTP1_1_ftp1_0()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://ftp.microsoft.com");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.0");
            wr.ProtocolVersion = new Version(1, 0);

            HttpServer server = new HttpServer("http", 8080, ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();
                System.Net.WebHeaderCollection wrs = server.RequestHeaders;

                SetCommonHttpResponseHeaders_1_0(ref wrs);

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                WebHeaderCollection wrc = wr.Headers;

                VerifyHttpResponseHeaders(wrc, wrs);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                StopServerListener(ref server);
                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:47,代码来源:HttpResponseHeaderTests.cs

示例11: ValidDefaultTestGetHTTPResponseHeaderAfterCreateHTTP1_1_https

        //This test case get System.NotSupportedException
        public MFTestResults ValidDefaultTestGetHTTPResponseHeaderAfterCreateHTTP1_1_https()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("https://127.0.0.1:443/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("https", 443, ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();
                System.Net.WebHeaderCollection wrs = server.RequestHeaders;

                SetCommonHttpResponseHeaders(ref wrs);

                //Get System.NotSupportedException when retrive response --  Need further investigation
                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                WebHeaderCollection wrc = wr.Headers;

                VerifyHttpResponseHeaders(wrc, wrs);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                StopServerListener(ref server);
                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:49,代码来源:HttpResponseHeaderTests.cs

示例12: DefaultTestHTTPStatusCodeHTTP1_1_Unauthorized

        public MFTestResults DefaultTestHTTPStatusCodeHTTP1_1_Unauthorized()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + HttpServer.s_CurrentPort.ToString() + "/webpages/Unauth.html");  //expect 401 - Unauthorized 
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>DefaultTestHTTPStatusCodeHTTP1_1_Unauthorized</body></html>"
            };

            try
            {
                // Setup server
                server.StartServer();

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                Log.Comment("Expect StatusCode - Unauthorized ");
                if (HttpStatusCode.Unauthorized != response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = Unauthorized but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:49,代码来源:HttpStatusCodeTests.cs

示例13: TestHTTPStatusCodeHTTP1_1_NonAuthoritativeInformation

        public MFTestResults TestHTTPStatusCodeHTTP1_1_NonAuthoritativeInformation()
        {
            MFTestResults result = MFTestResults.Pass;


            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + HttpServer.s_CurrentPort.ToString() + "/webpages/nonauthInfo.html");  //expect 203 - NonAuthoritativeInformation
            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            wr.Method = "GET";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>TestHTTPStatusCodeHTTP1_1_NonAuthoritativeInformation</body></html>"
            };

            try
            {
                // Setup server
                server.StartServer();

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                Log.Comment("Expect StatusCode - NonAuthoritativeInformation");
                if ((int)HttpStatusCode.NonAuthoritativeInformation != (int)response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = NonAuthoritativeInformation but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }
                Log.Comment("Receive " + response.StatusDescription);
                response.Close();

            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {

                //Stop server
                server.StopServer();
            }

            return result;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:52,代码来源:HttpStatusCodeTests.cs


注:本文中的Microsoft.SPOT.Platform.Tests.HttpServer.StartServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。