用于单元测试的模拟 SSL HttpRequest
我正在尝试模拟 SSL HttpRequest,但我无法弄清楚如何在请求对象中将协议设置为 HTTPS。 我从 Phil Haack 的一个例子开始: http://haacked.com/archive/2005/06/11/simulated_httpcontext。 aspx
有没有办法将请求设置为SSL?
public class MockHttpRequest : SimpleWorkerRequest
{
private string _Host;
public MockHttpRequest(
string appVirtualDir, string appPhysicalDir, string page, string query, TextWriter output, string host) :
base(appVirtualDir, appPhysicalDir, page, query, output)
{
if (string.IsNullOrEmpty(host))
{
throw new ArgumentException("Host must be provided.");
}
_Host = host;
}
}
public static class UnitTestingHelper
{
public static HttpContext CreateMockHttpContext(string host, string page)
{
string appVirtualDir = "/";
string appPhysicalDir = @"C:\Documents and Settings\user\My Documents\Workspace\Project\";
string query = string.Empty;
TextWriter output = null;
MockHttpRequest request
= new MockHttpRequest(appVirtualDir, appPhysicalDir, "default.aspx", query, output, host);
// How to make the request HTTPS?
HttpContext context = new HttpContext(request);
return new HttpContext(request);
}
}
I'm trying to mock out an SSL HttpRequest but I'm having trouble figuring out how to set the protocol to HTTPS in the request object. I got started from an example from Phil Haack here:
http://haacked.com/archive/2005/06/11/simulating_httpcontext.aspx
Is there a way to set the request to SSL?
public class MockHttpRequest : SimpleWorkerRequest
{
private string _Host;
public MockHttpRequest(
string appVirtualDir, string appPhysicalDir, string page, string query, TextWriter output, string host) :
base(appVirtualDir, appPhysicalDir, page, query, output)
{
if (string.IsNullOrEmpty(host))
{
throw new ArgumentException("Host must be provided.");
}
_Host = host;
}
}
public static class UnitTestingHelper
{
public static HttpContext CreateMockHttpContext(string host, string page)
{
string appVirtualDir = "/";
string appPhysicalDir = @"C:\Documents and Settings\user\My Documents\Workspace\Project\";
string query = string.Empty;
TextWriter output = null;
MockHttpRequest request
= new MockHttpRequest(appVirtualDir, appPhysicalDir, "default.aspx", query, output, host);
// How to make the request HTTPS?
HttpContext context = new HttpContext(request);
return new HttpContext(request);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 HttpContext.Request 中的某处有一个 IsSecureConnection 属性需要为 true。
I think there's a IsSecureConnection property somewhere in HttpContext.Request that needs to be true.