Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何模拟具有Fiddler核心的服务器?_C#_Fiddler_Fiddlercore - Fatal编程技术网

C# 如何模拟具有Fiddler核心的服务器?

C# 如何模拟具有Fiddler核心的服务器?,c#,fiddler,fiddlercore,C#,Fiddler,Fiddlercore,我正在尝试调试一个应用程序,但不将fiddler设置为其代理 为此,我设置了一个基于fiddler.core的应用程序,它驻留在网络中的另一台计算机上,并在hosts文件中添加了一个条目 以下是应用程序的代码: private static Proxy googleEndpoint; static void Main(string[] args) { List<Fiddler.Session> oAllSessions =new List&l

我正在尝试调试一个应用程序,但不将fiddler设置为其代理

为此,我设置了一个基于fiddler.core的应用程序,它驻留在网络中的另一台计算机上,并在hosts文件中添加了一个条目

以下是应用程序的代码:

    private static Proxy googleEndpoint;

    static void Main(string[] args)
    {
        List<Fiddler.Session> oAllSessions =new List<Session>();

        Fiddler.FiddlerApplication.BeforeRequest += (i) => Console.WriteLine("Before request: "+i.fullUrl);
        FiddlerApplication.AfterSessionComplete += (i) =>
        {
            Console.WriteLine("After request: "+i.fullUrl);
            lock (oAllSessions)
            {
                oAllSessions.Add(i);
            }
        };

        //https://www.google.com.ua/

        googleEndpoint = FiddlerApplication.CreateProxyEndpoint(443, true, "www.google.com.ua");
        if (null != googleEndpoint)
        {
            Console.WriteLine("google.com.ua endpoint mounted");
        }
        else
        {
            Console.WriteLine("failed to mount google.com.ua endpoint");
        }

        Console.ReadKey();
        SaveSessionsToDesktop(oAllSessions);
    }

    private static void SaveSessionsToDesktop(List<Fiddler.Session> oAllSessions)
    {
        bool bSuccess = false;
        string sFilename = DateTime.Now.ToString("hh-mm-ss") + ".saz";
        try
        {
            try
            {
                Monitor.Enter(oAllSessions);
                TranscoderTuple oExporter = FiddlerApplication.oTranscoders.GetExporter("SAZ");

                if (null != oExporter)
                {
                    Dictionary<string, object> dictOptions = new Dictionary<string, object>();
                    dictOptions.Add("Filename", sFilename);
                    // dictOptions.Add("Password", "pencil");

                    bSuccess = FiddlerApplication.DoExport("SAZ", oAllSessions.ToArray(), dictOptions, null);
                }
                else
                {
                    Console.WriteLine("Save failed because the SAZ Format Exporter was not available.");
                }
            }
            finally
            {
                Monitor.Exit(oAllSessions);
            }

            WriteCommandResponse(bSuccess ? ("Wrote: " + sFilename) : ("Failed to save: " + sFilename));
        }
        catch (Exception eX)
        {
            Console.WriteLine("Save failed: " + eX.Message);
        }
    }

    public static void WriteCommandResponse(string s)
    {
        ConsoleColor oldColor = Console.ForegroundColor;
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine(s);
        Console.ForegroundColor = oldColor;
    }
私有静态代理googleEndpoint;
静态void Main(字符串[]参数)
{
List oAllSessions=新列表();
Fiddler.FiddlerApplication.BeforeRequest+=(i)=>Console.WriteLine(“请求前:+i.fullUrl”);
FiddleApplication.AfterSessionComplete+=(i)=>
{
Console.WriteLine(“请求后:+i.fullUrl”);
锁定(oAllSessions)
{
加入(i);
}
};
//https://www.google.com.ua/
googleEndpoint=FiddlerApplication.CreateProxyEndpoint(443,true,“www.google.com.ua”);
if(null!=谷歌端点)
{
Console.WriteLine(“google.com.ua端点安装”);
}
其他的
{
WriteLine(“未能装载google.com.ua端点”);
}
Console.ReadKey();
SaveSessionsToDesktop(oAllSessions);
}
私有静态void SaveSessionsToDesktop(列出所有会话)
{
bool bsucces=假;
字符串sFilename=DateTime.Now.ToString(“hh-mm-ss”)+“.saz”;
尝试
{
尝试
{
Monitor.Enter(oAllSessions);
TranscoderTuple oExporter=FiddleApplications.oTranscoders.GetExporter(“SAZ”);
if(null!=oExporter)
{
Dictionary dictOptions=新建Dictionary();
添加(“文件名”,sFilename);
//添加(“密码”、“铅笔”);
bSuccess=FiddlerApplication.DoExport(“SAZ”,oAllSessions.ToArray(),dictOptions,null);
}
其他的
{
WriteLine(“保存失败,因为SAZ格式导出器不可用。”);
}
}
最后
{
监视器。退出(oAllSessions);
}
WriteCommand响应(bSuccess?(“写入:+sFilename:”)(“未能保存:+sFilename”);
}
捕获(例外情况除外)
{
Console.WriteLine(“保存失败:+eX.Message”);
}
}
公共静态void writeCommand响应(字符串s)
{
ConsoleColor oldColor=Console.ForegroundColor;
Console.ForegroundColor=ConsoleColor.Yellow;
控制台。写入线(s);
Console.ForegroundColor=oldColor;
}
但是当我试图访问
https://www.google.com.ua
从目标机器发出的请求现在超时

Fiddler应用程序显示它已在
BeforeRequest
事件中收到请求,但它从未发送回复(
AfterSessionComplete
从未被调用)

为什么会发生这种情况?我如何修复它


如何对端口80执行相同操作?

我相信您会记住一个事实,即除非您将客户端重新配置为信任FiddlerServer的根证书,否则它不会向FiddlerCore发出HTTPS请求。它将在获得拦截证书后立即关闭连接


如果附加BeforeResponse事件处理程序,您会看到什么?它着火了吗

我确实重新配置了客户端。我的问题是请求超时。