1

I have task crate tracer which will store raw HTTP traffic with headers and body between localhost and SOAP API. I found that good solution for that is FiddlerCore. Application work only with HTTPS. Currently I got only my request. But want to see response from SOAP API.

I initialize FolderCore proxy when application start:

        CONFIG.bCaptureCONNECT = true;
        CONFIG.IgnoreServerCertErrors = false;
        FiddlerApplication.Prefs.SetStringPref("fiddler.config.path.makecert", @"c:\Program Files (x86)\Fiddler2\Makecert.exe");
        FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
        if (!CertMaker.rootCertExists())
        {
            if (!CertMaker.createRootCert())
            {
                throw new Exception("Unable to create cert for FiddlerCore.");
            }
            X509Store certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
            certStore.Open(OpenFlags.ReadWrite);
            try
            {
                certStore.Add(CertMaker.GetRootCertificate());
            }
            finally
            {
                certStore.Close();
            }
        }

Method AfterSessionComplete:

    private void FiddlerApplication_AfterSessionComplete(Session sess)
    {
        // Ignore HTTPS connect requests
        if (sess.RequestMethod == "CONNECT")
        {
            return; 
        }

        if (sess == null || sess.oRequest == null || sess.oRequest.headers == null)
        {
            return; 
        }
        // Request
        string headers = sess.oRequest.headers.ToString();
        var reqBody = sess.GetRequestBodyAsString();

        // Response
        var resHeaders = sess.oResponse.headers.ToString();
        var resBody = sess.GetResponseBodyAsString();

        // if you wanted to capture the response
        //string respHeaders = session.oResponse.headers.ToString();
        //var respBody = session.GetResponseBodyAsString();

        // replace the HTTP line to inject full URL
        string firstLine = sess.RequestMethod + " " + sess.fullUrl + " " + sess.oRequest.headers.HTTPVersion;
        int at = headers.IndexOf("\r\n");
        if (at < 0)
            return;
        headers = firstLine + "\r\n" + headers.Substring(at + 1);

        string output = headers + "\r\n" +
                        (!string.IsNullOrEmpty(reqBody) ? reqBody + "\r\n" : string.Empty) + "\r\n\r\n";

    }

In web.config added:

<defaultProxy>
  <proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false" />
</defaultProxy>
korvinko
  • 650
  • 3
  • 10
  • 22
  • Your title refers to HTTPS, but your question specifically excludes HTTPS. Would you edit your title to remove the S from HTTPS please. – WizzleWuzzle Oct 05 '16 at 20:22

1 Answers1

0

Is was super easy. Used sess.oResponse.headers and sess.GetResponseBodyAsString() for this

    var resHeaders = sess.oResponse.headers.ToString();
    var resBody = sess.GetResponseBodyAsString();
korvinko
  • 650
  • 3
  • 10
  • 22