Using Fiddler To Replay an AJAX (xmlhttp) Request

 

The Problem

I use to spend a lot of time writing throw away JavaScript code to test AJAX (XMLHttpRequest or Asynchronous JavaScript and XML) type requests to my hosted web services.  that is, on my ASP.NET server, I have services that look like the following (Microsoft ASP.NET MVC projects):

[HttpPost]
[NoCache]
public JsonResult GetEmailByPerson(long addressBookEntryId, 
    string existingEmailDetailIds, int? start, int? limit,
    bool? emailNotViewed = null, bool? emailNotDeleted = null,
    bool? forceDataToHtmlBody = false)
{
    Utils.AuthorityLevel userAuthorityLevel = Utils.GetUserAuthorityLevel();
    if (userAuthorityLevel == Utils.AuthorityLevel.None)
    {
        return Json(new
        {
            Message = "Requires Authentication",
            Success = false
        }, JsonRequestBehavior.DenyGet);
    }

 

The problem is that when things don’t quite work as I expect, I need to write little JavaScript snippets of code to execute and write little error catching routines to see what is broken.

 

Fiddler Makes This Easy With No Hand Coding

Now, instead of having to make little snippets of code, here is all I have to do in Fiddler.

1.  Install Fiddler from Eric Lawrence (Pretty obvious)  http://www.fiddler2.com/fiddler2/

2.  Run Fiddler (by default, it captures your web traffic).  You’ll see a screen like the following after you have run Fiddler, then browse to your web site that captures this traffic.

image

Notice we have selected the http Ajax call (see the status bar) of the call I want to replay.

3.  Select on the right side the “Composer” tab (it will show you your current request)

image

4. Now, for that not so intuitive part, but the past part.  Select the request on the left by holding the mouse down on that request and drag it to the right side. There is a big hint below the composer tab label about this, but somehow I never noticed it before.

image

5. Now, change the sub tab on the right tot the “RAW” sub tab  as follows and you can change any of the parameter values you want and simply press “Execute”.

image

 

That’s it!  the Ajax request is replayed with your new parameters and you can look at the new result in fiddler just like always.

 

HTH’s!

About Peter Kellner

Peter is a software professional specializing in mobile and web technologies. He has also been a Microsoft MVP for the past 7 years. To read more about Peter Kellner and his experience click here. For information about how Peter Kellner might be able to help you with your project click here.

Follow me:


Comments

  1. Thanks for the tips Eric! I specialize in doing things the long way so I’m not surprised there are at least two other easier ways to do it. Very happy you built Fiddler. It’s a huge help for me in understanding what is going on.

  2. Thanks for the nice writeup, Peter!

    You can change header or body values from the PARSED tab too– you generally won’t need to use the RAW tab for anything. You also don’t need to drag/drop if you don’t want to; right-click the Session and choose Replay > From Composer.

    To replay a request without changing anything, select it in the list and hit the R key.

Follow

Get every new post delivered to your Inbox

Join other followers: