gpt4 book ai didi

unit-testing - 用于单元测试的模拟 SSL HttpRequest

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:03 25 4
gpt4 key购买 nike

我正在尝试模拟 SSL HttpRequest,但我无法弄清楚如何在请求对象中将协议(protocol)设置为 HTTPS。我从 Phil Haack 的一个例子开始: http://haacked.com/archive/2005/06/11/simulating_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);
}
}

最佳答案

我认为 HttpContext.Request 中某处有一个 IsSecureConnection 属性需要为真。

关于unit-testing - 用于单元测试的模拟 SSL HttpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/986785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com