尝试使用.NetStandard库使用FiddlerCore捕获来自浏览器的所有流量。 以下是我的内容:
public class ProxyConfig
{
private const string SecureEndpointHostname = "localhost";
private readonly int _secureEndpointPort = 18888;
private static readonly ICollection<Session> AllSessions = new List<Session>();
private static Fiddler.Proxy _secureEndpoint;
private static readonly LoggerCnx Logger = new LoggerCnx();
public void SetupProxyListener()
{
// This is a workaround for known issue in .NET Core - https://github.com/dotnet/coreclr/issues/12668
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
FiddlerApplication.BeforeRequest += session =>
{
// In order to enable response tampering, buffering mode MUST
// be enabled; this allows FiddlerCore to permit modification of
// the response in the BeforeResponse handler rather than streaming
// the response to the client as the response comes in.
session.bBufferResponse = false;
lock (AllSessions)
{
AllSessions.Add(session);
}
};
Logger.Info($"Starting {FiddlerApplication.GetVersionString()}...");
CONFIG.IgnoreServerCertErrors = true;
CONFIG.bCaptureCONNECT = true;
FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true);
FiddlerCoreStartupFlags startupFlags = FiddlerCoreStartupFlags.Default;
startupFlags = (startupFlags | FiddlerCoreStartupFlags.DecryptSSL);
FiddlerApplication.Startup(BaseConfiguration.ProxyPort, startupFlags);
Logger.Info("Created endpoint listening on port {0}", BaseConfiguration.ProxyPort);
Logger.Info("Starting with settings: [{0}]", startupFlags);
Logger.Info("Gateway: {0}", CONFIG.UpstreamGateway.ToString());
// Create a HTTPS listener, useful for when FiddlerCore is masquerading as a HTTPS server
// instead of acting as a normal CERN-style proxy server.
_secureEndpoint = FiddlerApplication.CreateProxyEndpoint(_secureEndpointPort, true, SecureEndpointHostname);
if (null != _secureEndpoint)
{
Logger.Info("Created secure endpoint listening on port {0}, using a HTTPS certificate for '{1}'", _secureEndpointPort, SecureEndpointHostname);
}
}
}
一切似乎在Windows上运行正常,所有流量都被捕获,HTTP和HTTPS。
当我在Linux上运行代码时试图做同样的事情时出现了问题(在VM和Linux变种器上尝试过,Ubuntu 16.04)。捕获HTTP流量但不支持HTTPS。
知道我错过了什么吗?