【问题标题】:Fiddler not capturing connections via proxyFiddler 未通过代理捕获连接
【发布时间】:2014-07-03 00:40:56
【问题描述】:

我有一个 C# 程序,它通过一些外部代理建立了一些连接。

Fiddler 无法捕获这些不使用 fiddler 作为代理的请求

有什么方法可以让这些连接首先以任何 C# 方式或 fiddler 设置方式通过 fiddler 进行?

【问题讨论】:

  • *.com/questions/18576947/… 不要在你的代码中使用代理
  • 我不只是在我的代码中使用一个代理,这个提琴手设置不能给我在 C# 编码中的灵活性。但这是一个很好的建议。谢谢
  • 您还可以在代码中使用 FiddlerCore 并以编程方式链接代理
  • 我刚用谷歌搜索。我是否需要自己实现 UI 才能像 fiddler 一样轻松调试流量?
  • 是的..更好的写入文件....

标签: c# proxy fiddler


【解决方案1】:

您可以使用 FiddlerCore 并链接代理..

Proxy p = new Proxy(new List<string>() { "122.129.107.3:8080" }); //real proxies...

WebClient wc = new WebClient();
wc.Proxy = new WebProxy("127.0.0.1", 8888); //local proxy(fiddler core)
wc.Headers["User-Agent"] = "SO/1.0";
var html = wc.DownloadString("http://google.com");

public class Proxy
{
    List<string> _Proxies = null;
    public Proxy(List<string> proxies)
    {
        _Proxies = proxies;
        Fiddler.FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest;
        Fiddler.FiddlerApplication.Startup(8888, false, true);
    }

    static long _Sequence = 0;
    void FiddlerApplication_BeforeRequest(Fiddler.Session oSession)
    {
        var sequence = Interlocked.Increment(ref _Sequence);
        string proxy = _Proxies[(int)(sequence % _Proxies.Count)];

        oSession["x-OverrideGateway"] = proxy;

        Console.WriteLine(String.Format("Proxy[{0}]> {1}", proxy, oSession.host));
    }
}

只需将代理列表传递给此类。它将为每个请求使用不同的请求。您的客户将只使用这个 Proxy

【讨论】:

  • 非常详细的解决方案
  • 没有必要为此使用 FiddlerCore;您可以使用 Fiddler 本身。在“规则”>“自定义规则”>“OnBeforeRequest”中设置x-OverrideGateway
  • @EricLaw 如果您查看代码,它会随每个请求更改代理(请参阅构造函数参数List&lt;string&gt; proxies)。你可以用提琴手做到这一点吗?顺便说一句:这已经在上面的 cmets 中讨论过了。
  • 当然你可以用 Fiddler 本身来做到这一点;按照说明将代码放在OnBeforeRequest 函数中。
  • @EricLaw 谢谢埃里克。看来没必要继续这种无意义的讨论了。