1

我正在尝试使用 Fiddler.Core 创建一个反向代理,我们可以使用它通过 http(s) 重播第三方请求。

该库适用于http,对于https,我似乎缺少一步,因为重播响应似乎只是超时。

这是规格的代码:

[TestClass]
public class Verify_basic_proxy_functionality
{
    WebClient WC;
    Proxy SUT;

    [TestInitialize]
    public void Init()
    {
        SUT = new Proxy();
        SUT.InsertSession(Url:"http://proxy/ping",ResponseBody:"pong");
        var uri = SUT.Startup(9100,IsRecording: false);
        WC = new WebClient() { Proxy = new WebProxy(uri)};
    }

    [TestMethod]
    public void Ping_should_return_pong()
    {
        WC.DownloadString("http://proxy/ping").ShouldBe("pong");
    }

    [TestMethod]
    [ExpectedException(typeof(WebException))]
    public void Pang_should_return_error()
    {
        WC.DownloadString("http://proxy/pang");
    }

    [TestMethod]
    public void Http_reverse_proxy_should_work()
    {
        SUT.IsRecording = true;
        var http_url = "http://httpbin.org/ip";
        var initial_result = WC.DownloadString(http_url);
        initial_result.ShouldContain("origin");
        SUT.IsRecording = false;
        var result = WC.DownloadString(http_url);
        result.ShouldBe(initial_result);
    }

    // This one fails with a timeout... Probably need to close the connection or similar?
    [TestMethod]
    public void Https_reverse_proxy_should_work()
    {
        SUT.IsRecording = true;
        var https_url = "https://httpbin.org/ip"; 
        var initial_result = WC.DownloadString(https_url);
        initial_result.ShouldContain("origin");
        SUT.IsRecording = false;
        var result = WC.DownloadString(https_url);
        result.ShouldBe(initial_result);
    }
}

可以在以下要点找到代理的代码:https ://gist.github.com/ToJans/5082560

我想我可能需要为 https(即编码)添加一个额外的步骤。AFAIK fiddler.core 在我拦截OnValidateServerCertificate并始终返回 true 时忽略证书错误。

谁能告诉我我在这里做错了什么?

4

1 回答 1

1

好吧,我的一位同事指出了我思维中的一个缺陷。在为 SSL 重播时,您不应该记录/重播 CONNECT !!!

MITM 代理现在可以使用.....

于 2013-03-06T09:57:27.503 回答