Exporting API calls through fiddler

7 posts, 1 answers
  1. Avner
    Avner avatar
    5 posts
    Member since:
    Feb 2014

    Posted 05 Feb 2014 Link to this post

    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

  2. Answer
    EricLaw
    EricLaw avatar
    67 posts
    Member since:
    Oct 2012

    Posted 05 Feb 2014 in reply to Avner Link to this post

    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
  3. Avner
    Avner avatar
    5 posts
    Member since:
    Feb 2014

    Posted 06 Feb 2014 in reply to EricLaw Link to this post

    Thanks!
    i started to build a fiddler extension, ill update when its done.
  4. Avner
    Avner avatar
    5 posts
    Member since:
    Feb 2014

    Posted 06 Feb 2014 Link to this post

    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




  5. EricLaw
    EricLaw avatar
    67 posts
    Member since:
    Oct 2012

    Posted 07 Feb 2014 in reply to Avner Link to this post

    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.
  6. Avner
    Avner avatar
    5 posts
    Member since:
    Feb 2014

    Posted 09 Feb 2014 in reply to EricLaw Link to this post

    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!

  7. Avner
    Avner avatar
    5 posts
    Member since:
    Feb 2014

    Posted 09 Feb 2014 in reply to EricLaw Link to this post

    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!

Back to Top