2017-03-10 3 views
1

나는 fiddlercore DEMO를 다운로드 받았고 응용 프로그램에서 WPF에 의존하는 응용 프로그램을 사용하려고합니다. 그런 다음 응용 프로그램에서 https가 응답하는 자원을 캡처 할 수 없다는 질문에 대답합니까? 바로 아래에서 enter image description herehttps를 피들러 코어를 통해 어떻게 캡처 할 수 있습니까?

내 코드 :

using Fiddler; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading; 
using System.Windows; 

namespace operateToolWPF.Utils 
{ 
    public class MyFiddler 
    { 
     static Proxy oSecureEndpoint; 
     static string sSecureEndpointHostname = "localhost"; 
     static int iSecureEndpointPort = 7777; 
     public List<Fiddler.Session> oAllSessions { get; set; } 


     public void DoQuit() 
     { 
      if (null != oSecureEndpoint) oSecureEndpoint.Dispose(); 
      Fiddler.FiddlerApplication.Shutdown(); 
      //Thread.Sleep(500); 
     } 
     private string CalcResponseSize(Session oS) 
     { 
      if (null == oS.oResponse) return String.Empty; 
      var cBytesOut = 0; 

      if (null != oS.responseBodyBytes) cBytesOut += oS.responseBodyBytes.Length; 
      if ((null != oS.oResponse) && (null != oS.oResponse.headers)) cBytesOut += 
       oS.oResponse.headers.ByteCount(); 
      return cBytesOut.ToString(); 
     } 

     public void WriteSessionList(List<Fiddler.Session> oAllSessions) 
     { 
      ConsoleColor oldColor = Console.ForegroundColor; 
      Console.ForegroundColor = ConsoleColor.White; 
      Console.WriteLine("Session list contains..."); 
      try 
      { 
       Monitor.Enter(oAllSessions); 
       foreach (Session oS in oAllSessions) 
       { 
        Console.Write(String.Format("{0} {1} {2} {3} {4} {5} {6}\n", oS.id, oS.oRequest.headers.HTTPMethod, oS.fullUrl, oS.responseCode, oS.oResponse.MIMEType, (oS.Timers.ClientBeginResponse - oS.Timers.ClientBeginRequest), CalcResponseSize(oS))); 
       } 
      } 
      finally 
      { 
       Monitor.Exit(oAllSessions); 
      } 
      Console.WriteLine(); 
      Console.ForegroundColor = oldColor; 
     } 


     public void DoFiddler() 
     { 
      oAllSessions = new List<Fiddler.Session>(); 
      //if (!Fiddler.CertMaker.rootCertExists()) 
      //{ 
      // if (!Fiddler.CertMaker.createRootCert()) 
      // { 
      //  throw new Exception("Unable to create cert for FiddlerCore."); 
      // } 
      //} 

      //if (!Fiddler.CertMaker.rootCertIsTrusted()) 
      //{ 
      // if (!Fiddler.CertMaker.trustRootCert()) 
      // { 
      //  throw new Exception("Unable to install FiddlerCore's cert."); 
      // } 
      //} 

      #region AttachEventListeners 
      Fiddler.FiddlerApplication.OnNotification += delegate(object sender, NotificationEventArgs oNEA) { 
       Console.WriteLine("** NotifyUser: " + oNEA.NotifyString); 
      }; 
      Fiddler.FiddlerApplication.Log.OnLogString += delegate(object sender, LogEventArgs oLEA) { 
       Console.WriteLine("** LogString: " + oLEA.LogString); 
      }; 

      Fiddler.FiddlerApplication.BeforeRequest += delegate(Fiddler.Session oS) 
      { 
       //Console.WriteLine("Fiddler.FiddlerApplication.BeforeRequest"); 
       oS.bBufferResponse = true; 
       Monitor.Enter(oAllSessions); 
       oAllSessions.Add(oS); 
       //Console.Write(String.Format("{0} {1} {2} {3} {4} {5} {6}\n", oS.id, oS.oRequest.headers.HTTPMethod, oS.fullUrl, oS.responseCode, oS.oResponse.MIMEType, (oS.Timers.ClientBeginResponse - oS.Timers.ClientBeginRequest), CalcResponseSize(oS))); 
       Monitor.Exit(oAllSessions); 
       oS["X-AutoAuth"] = "(default)"; 
       if ((oS.oRequest.pipeClient.LocalPort == iSecureEndpointPort) && (oS.hostname == sSecureEndpointHostname)) 
       { 
        oS.utilCreateResponseAndBypassServer(); 
        oS.oResponse.headers.SetStatus(200, "Ok"); 
        oS.oResponse["Content-Type"] = "text/html; charset=UTF-8"; 
        oS.oResponse["Cache-Control"] = "private, max-age=0"; 
        oS.utilSetResponseBody("<html><body>Request for httpS://" + sSecureEndpointHostname + ":" + iSecureEndpointPort.ToString() + " received. Your request was:<br /><plaintext>" + oS.oRequest.headers.ToString()); 
       } 
      }; 

      Fiddler.FiddlerApplication.AfterSessionComplete += delegate(Fiddler.Session oS) 
      { 
       //Console.WriteLine("Fiddler.FiddlerApplication.AfterSessionComplete"); 
       //Console.Title = ("Session list contains: " + oAllSessions.Count.ToString() + " sessions"); 
       //DoQuit(); 
      }; 

      // Tell the system console to handle CTRL+C by calling our method that 
      // gracefully shuts down the FiddlerCore. 
      // 
      // Note, this doesn't handle the case where the user closes the window with the close button. 
      // See http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx for info on that... 
      // 
      #endregion AttachEventListeners 
      string sSAZInfo = "NoSAZ"; 
#if SAZ_SUPPORT 
      sSAZInfo = Assembly.GetAssembly(typeof(Ionic.Zip.ZipFile)).FullName; 

      DNZSAZProvider.fnObtainPwd =() => 
      { 
       Console.WriteLine("Enter the password (or just hit Enter to cancel):"); 
       string sResult = Console.ReadLine(); 
       Console.WriteLine(); 
       return sResult; 
      }; 

      FiddlerApplication.oSAZProvider = new DNZSAZProvider(); 
#endif 

      Console.WriteLine(String.Format("Starting {0} ({1})...", Fiddler.FiddlerApplication.GetVersionString(), sSAZInfo)); 
      Fiddler.CONFIG.IgnoreServerCertErrors = false; 
      FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true); 

      FiddlerCoreStartupFlags oFCSF = FiddlerCoreStartupFlags.Default; 
      int iPort = 8877; 
      Fiddler.FiddlerApplication.Startup(iPort, oFCSF); 
      FiddlerApplication.Log.LogFormat("Created endpoint listening on port {0}", iPort); 

      FiddlerApplication.Log.LogFormat("Starting with settings: [{0}]", oFCSF); 
      FiddlerApplication.Log.LogFormat("Gateway: {0}", CONFIG.UpstreamGateway.ToString()); 

      oSecureEndpoint = FiddlerApplication.CreateProxyEndpoint(iSecureEndpointPort, true, sSecureEndpointHostname); 
      if (null != oSecureEndpoint) 
      { 
       FiddlerApplication.Log.LogFormat("Created secure endpoint listening on port {0}, using a HTTPS certificate for '{1}'", iSecureEndpointPort, sSecureEndpointHostname); 
      } 


     } 
    } 
} 

가 나를 도울 수 감사합니다!

답변

0

희망이 모든 것을 해결할 수 있기를 바랍니다.이 데모 애플리케이션의 문제점 HTTP 및 HTTPS 요청을 추적하는 방법을 명확하게 설명했습니다. AfterSessionComplete 이벤트를 직접들을 수 있지만 HTTPS의 경우에는 Fiddler 코어를 설치해야합니다. 이 인증서 https://weblog.west-wind.com/posts/2014/jul/29/using-fiddlercore-to-capture-http-requests-with-net

+0

대단히 고마워요! 네 진보가 나에게 유용 했어! 너무 길어서 많이 이해할 수는 없지만! –

+0

당신이 물어볼 수있는 피들러 코어에 의심의 여지가 있다면 ... !! 또는 당신이 어려운 것을 발견하면. –

+0

대단히 감사합니다! –

관련 문제