This is a migrated thread and some comments may be shown as answers.

Exporting API calls through fiddler

6 Answers 59 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Avner
Top achievements
Rank 1
Avner asked on 05 Feb 2014, 11:52 AM
Hi, I'm not sure it's the right place to post this question, but any help will be good

I'm trying to export the raw data from API responses using fiddler. 

i want to do it in order to verify the content from the response in real time, for uses of automation testing,
anyone has an idea how can i do it?

Thanks,
Avner

6 Answers, 1 is accepted

Sort by
0
Accepted
EricLaw
Top achievements
Rank 1
answered on 05 Feb 2014, 07:27 PM
Hi, Avner--
Typically, you'd use either FiddlerScript or a .NET-based IFiddlerExtension to look at the response's body inside the OnBeforeResponse event handler.
-Eric
0
Avner
Top achievements
Rank 1
answered on 06 Feb 2014, 10:27 AM
Thanks!
i started to build a fiddler extension, ill update when its done.
0
Avner
Top achievements
Rank 1
answered on 06 Feb 2014, 04:25 PM
Hi again
I'm having a problem with loading the extension with fiddler.
i can see in ProcXp that fiddler.exe is using the dll file i'v created, but still it doesn't run it from some reason. also tried to attach the fiddler process to visual studio (after enabling debug) and placed some breakpoints, but it didn't reach them.

what i'v done:
added a refrence to Fiddler and to System.Windows.Forms
added a post build event to "%userprofile%\My Documents\Fiddler2\Scripts\$(TargetFilename)"
added a reference to the dll path in fiddler (Tools>Fiddler options > Extensions)
changed the CLR to  v2.0 (in the compiler) and i have the 2.0 SP1 installed (up to 4.0)
still, after restarting fiddler, i can't see my dll in the fiddler's extensions list, and it does not work.

i'm using this class:

using System;
using System.Collections.Generic;
using System.Text;

namespace ClassLibrary1
{
    using System;
    using System.Windows.Forms;
    using Fiddler;
    using System.IO;
    

    // Extension requires Fiddler 2.2.8.6+ because it uses types introduced in v2.2.8...
    [assembly: Fiddler.RequiredVersion("2.2.8.6")]

    public class ClassLibrary1 : IFiddlerExtension    // Ensure class is public, or Fiddler won't see it!
    {
        string sUserAgent = "";

        public ClassLibrary1()
        {
            
            FiddlerApplication.Prefs.SetBoolPref("fiddler.debug.extensions.showerrors",true);
            FiddlerApplication.Prefs.SetBoolPref("fiddler.debug.extensions.verbose", true);
            using (StreamWriter sw = File.CreateText("SpinAndCollectTest"))
            {
                sw.Write("Test123");
            }
            
            /* NOTE: It's possible that Fiddler UI isn't fully loaded yet, so don't add any UI in the constructor.

               But it's also possible that AutoTamper* methods are called before OnLoad (below), so be
               sure any needed data structures are initialized to safe values here in this constructor */

            sUserAgent = "Violin";
        }

        public void OnLoad()
        {
            using (StreamWriter sw = File.CreateText("SpinAndCollectTest"))
            {
                sw.Write("Test123");
            }
        }
        public void OnBeforeUnload() { }

        public void AutoTamperRequestBefore(Session oSession)
        {
            oSession.oRequest["User-Agent"] = sUserAgent;
                    }
        public void AutoTamperRequestAfter(Session oSession) {            
        }
        public void AutoTamperResponseBefore(Session oSession) {

            MessageBox.Show("dll was read!");
           
            using (StreamWriter sw = File.CreateText("SpinAndCollectTest"))
            {
                sw.Write("Test123");
            }

            if (oSession.uriContains("SpinAndCollect"))
            {
                oSession.utilDecodeResponse();
                string responseBody = oSession.GetResponseBodyAsString();
                using (StreamWriter sw = File.CreateText("ParadiseSlotsApi"))
                {
                    sw.Write(responseBody);
                }
                
              
            }
        }
        public void AutoTamperResponseAfter(Session oSession) { }
        public void OnBeforeReturningError(Session oSession) { }
    }
   

}   
I would appreciate any help!
thanks,
Avner




0
EricLaw
Top achievements
Rank 1
answered on 07 Feb 2014, 06:01 AM
You might wish to start using one of the demo extensions whose source is available on the Fiddler add-ons list.
Implement IAutoTamper, not just IFiddlerExtension.
Set your preferences using QuickExec's about:config command. 
Look at the LOG tab to view error info after Fiddler loads.
Update your RequiredVersion attribute to 2.4.5.0 to prevent breaking on older clients.
0
Avner
Top achievements
Rank 1
answered on 09 Feb 2014, 04:00 PM
it works!
the problem was that i had to delete some references that CLR 3.5 didn't support. enabling the fiddler logs helped me figure it out.
Thanks a lot for the help!

0
Avner
Top achievements
Rank 1
answered on 09 Feb 2014, 04:00 PM
it works!
the problem was that i had to delete some references that CLR 3.5 didn't support. enabling the fiddler logs helped me figure it out.
Thanks a lot for the help!

Tags
Fiddler Classic
Asked by
Avner
Top achievements
Rank 1
Answers by
EricLaw
Top achievements
Rank 1
Avner
Top achievements
Rank 1
Share this question
or