本文整理汇总了C#中Microsoft.SPOT.Platform.Tests.HttpServer.StopServer方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.StopServer方法的具体用法?C# HttpServer.StopServer怎么用?C# HttpServer.StopServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.SPOT.Platform.Tests.HttpServer
的用法示例。
在下文中一共展示了HttpServer.StopServer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例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;
}
示例4: DefaultTestHTTPStatusCodeHTTP1_1_Unauthorized
public MFTestResults DefaultTestHTTPStatusCodeHTTP1_1_Unauthorized()
{
MFTestResults result = MFTestResults.Pass;
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + 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;
}
示例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;
}
示例6: 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;
}
示例7: TestHTTPStatusCodeHTTP1_1_TemporaryRedirect
public MFTestResults TestHTTPStatusCodeHTTP1_1_TemporaryRedirect()
{
MFTestResults result = MFTestResults.Pass;
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/webpages/tempRedir.html"); //expect 307 - TemporaryRedirect
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_TemporaryRedirect</body></html>"
};
try
{
// Setup server
server.StartServer();
HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
Log.Comment("Expect StatusCode - TemporaryRedirect");
if ((int)HttpStatusCode.TemporaryRedirect != (int)response.StatusCode)
{
Log.Exception("Expect HttpStatusCode = TemporaryRedirect 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: TestHTTPStatusCodeHTTP1_1_RequestUriTooLong
public MFTestResults TestHTTPStatusCodeHTTP1_1_RequestUriTooLong()
{
MFTestResults result = MFTestResults.Pass;
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + 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;
}
示例12: DefaultTestHTTPStatusCodeHTTP1_1_NotExistUriPath
public MFTestResults DefaultTestHTTPStatusCodeHTTP1_1_NotExistUriPath()
{
MFTestResults result = MFTestResults.Pass;
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + 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;
}