本文整理汇总了C#中Microsoft.SPOT.Platform.Tests.HttpServer类的典型用法代码示例。如果您正苦于以下问题:C# HttpServer类的具体用法?C# HttpServer怎么用?C# HttpServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpServer类属于Microsoft.SPOT.Platform.Tests命名空间,在下文中一共展示了HttpServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: StopServerListener
private MFTestResults StopServerListener(ref HttpServer server)
{
MFTestResults result = MFTestResults.Pass;
HttpListener mylistener = server.Listener;
try
{
mylistener.Stop();
}
catch (Exception ex)
{
Log.Exception("Exception when stop listener: " + ex.Message.ToString());
result = MFTestResults.Fail;
}
return result;
}
示例4: VerifyStream
private MFTestResults VerifyStream(HttpWebResponse response, HttpServer server)
{
MFTestResults result = MFTestResults.Pass;
using (System.IO.Stream responseStream = response.GetResponseStream())
{
if (responseStream != null)
{
string page = HttpTests.ReadStream("Client", responseStream);
if (page != server.ResponseString)
{
Log.Exception("Expect " + server.ResponseString + " but get " + responseStream.ToString());
result = MFTestResults.Fail;
}
}
else
{
result = MFTestResults.Fail;
Log.Exception("[Client] Expected stream, but got null");
}
}
return result;
}
示例5: 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;
}
示例6: 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;
}
示例7: ProcessException
private static void ProcessException(HttpListenerContext context, HttpServer server)
{
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
string strFilePath = GetPathFromURL(request.RawUrl == null ? "" : request.RawUrl);
// There is one particular URL that we process differently
if (strFilePath == "\\webexception\\ConnClose.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("ConnectionClosed", WebExceptionStatus.ConnectionClosed)).ToString();
}
if (strFilePath == "\\webexception\\KeepAliveFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("KeepAliveFailure", WebExceptionStatus.KeepAliveFailure)).ToString();
}
if (strFilePath == "\\webexception\\Pending.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("Pending", WebExceptionStatus.Pending)).ToString();
}
if (strFilePath == "\\webexception\\PipelineFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("PipelineFailure", WebExceptionStatus.PipelineFailure)).ToString();
}
if (strFilePath == "\\webexception\\ProxyNameResolutionFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("ProxyNameResolutionFailure", WebExceptionStatus.ProxyNameResolutionFailure)).ToString();
}
if (strFilePath == "\\webexception\\ReceiveFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("ReceiveFailure", WebExceptionStatus.ReceiveFailure)).ToString();
}
if (strFilePath == "\\webexception\\RequestCanceled.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("RequestCanceled", WebExceptionStatus.RequestCanceled)).ToString();
}
if (strFilePath == "\\webexception\\SecureChannelFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("SecureChannelFailure", WebExceptionStatus.SecureChannelFailure)).ToString();
}
if (strFilePath == "\\webexception\\SendFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("SendFailure", WebExceptionStatus.SendFailure)).ToString();
}
if (strFilePath == "\\webexception\\Success.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("Success", WebExceptionStatus.Success)).ToString();
}
if (strFilePath == "\\webexception\\Timeout.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("Timeout", WebExceptionStatus.Timeout)).ToString();
}
if (strFilePath == "\\webexception\\TrustFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("TrustFailure", WebExceptionStatus.TrustFailure)).ToString();
}
if (strFilePath == "\\webexception\\ConnectFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("ConnectFailure", WebExceptionStatus.ConnectFailure)).ToString();
}
if (strFilePath == "\\webexception\\NameResolutionFailure.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("NameResolutionFailure", WebExceptionStatus.NameResolutionFailure)).ToString();
}
if (strFilePath == "\\webexception\\ProtocolError.html")
{
// Throw the 'WebException' object with a message string, message status
server.ResponseString = (new WebException("ProtocolError", WebExceptionStatus.ProtocolError)).ToString();
}
if (strFilePath == "\\webexception\\ServerProtocolViolation.html")
{
// Throw the 'WebException' object with a message string, message status
//.........这里部分代码省略.........
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}