Fiddler Extension – Request to Code

This Fiddler extension generates C#, VB, or Python code to duplicate a web request.  You simply drag one or more Fiddler sessions into the “Code” tab or use the ‘r2c <partialURL1> <partialURL2> …’ QuickExec command and the extension will produce appropriate code that you can copy and paste into your program that reproduces those requests. You can also run the code directly from the extension tab.

Download: Fiddler Extension – Request To Code (version 2.1.0.0, 72.06 kB zipped)

This can be useful for a number of purposes:

  • Submit form data programmatically – fill out a form online once with Fiddler running, then use the extension to copy and paste the request code into your own program.  You could then make this request as many times and as often as you need to.
  • Easily codify web requests – request resources like RSS feeds, images, XML, etc… from your program.  Further modify the web requests to your needs.
  • Programmatically test differing header values – you can easily modify the request functions so that you can try varying values for various HTTP headers.  This way you can test your web site or web service against these various headers.
  • Run code directly from the Code tab – you can use the “Run Code” button to run the code currently in the Code tab.
  • Automatically generate code in conjunction with FiddlerCore – Reference both FiddlerCore and FiddlerCoreRequestToCode in your project and you can generate code and do whatever you want to do with it. For instance, you could write a file for each session you observe that contains the Request To Code code in it. See an example and learn more…

To Install:

  1. Copy FiddlerRequestToCode.dll from the .zip file into your Fiddler2\Scripts folder.
  2. You’ll need to restart Fiddler if it’s already running.

Questions/Comments – Please post on this Fiddler Google Group Discussion.
Read the Changelog.

31 Responses to Fiddler Extension – Request to Code

  1. Eugene says:

    Thank you very much! Excellent extension.

  2. Pingback: Creating a WebClient Request from an HTTP payload – d-fens GmbH

  3. Jay says:

    Hi Chad,

    Your extension is fabulous!!!!

    I wandted to know if there is a way to capture the response from a website that recevies the following response headers:

    Content-Type: application/octet-stream
    Content-Disposition: attachment; filename=000401013211.txt

    Typically, what I want to know is that can the file that is being sent to the browse, can that be read. I have been trying for a few days now, but have not been able to save a file that is being sent.

    Any help will be greatly appreciated.

    Jay

    • Chad says:

      Hi Jay. Sorry, I don’t understand what you’re asking to do. Can you clarify?

      The extension only generates the request, not response. You can then use the “Run” button to issue those requests and see the responses in Fiddler. You could add onto the generated code to inspect the responses Or, you can take the code generated and use it in any .NET application and then inspect the returned responses there.

  4. Mark says:

    Very nice Chad. I once spent many hours using network monitor so I could decode pages and hand craft code to navigate around my bank’s internet banking site. Then they re-implemented it and all that was worthless. Even worse they keep ‘improving’ it so the HTML keeps changing. If only they would implement some service interfaces! They do for their mobile app/site but it has limited functions.

    Between fiddler and your fiddler request to code extension, this sort of spelunking is much easier. A very heartful thank you.

    A couple of requests:
    o Fiddler 4 support
    o Break out the cookies into a CookieContainer
    o Break out QueryString into a name value collection (should be able to leverage the cookie parsing code to parse query string as well).

    Thanks,
    -mark

  5. DevTheo says:

    Hey Chad,

    Someone asked about releasing the source. I would like to see that happen. I would take your code and replace the C# codegen with codegen for some other language (like say Objective -C or Java). What you have done is nearly perfect.. just looking to save myself a little more time when I need something like this..

    DevTheo

  6. Apollo says:

    Hi Chad,
    I’ve installed the Fiddler4 beta (based on .net v4 I guess).
    After simply copying the FiddlerRequestToCode.dll to …\Fiddler4\Scripts folder as described the Code tab still doesn’t appear. A problem with .net v4?

  7. Albert says:

    Hi Chad, thanks for the extension, it’s simply awesome. My question is if you have any plan to release the source code? Thanks in advance

    • Chad says:

      Hi Albert. Thanks for the kind words! Sorry, I don’t plan on releasing the source code, at this time. Can I ask what you’re hoping to do with it? I might be able to help you out, anyways.

  8. Daniel says:

    Thanks Chad that is very cool. It may be worth mentioning that for POST request, it appears to only work for string data ( e.g. non-string data serialized to the request stream does not work correctly ). Albeit probably an uncommon use-case, it might be nice to include the raw post bytes in the code snippet. Either way, echoing others, genius extension :)

    • Chad says:

      Hi Dan – v2.0.0.0 of Request To Code now supports duplicating requests that POST binary data! Thanks for your report.

  9. Mohammad says:

    Thanks Chad for this great add-on. it works perfect. I’m just wondering to create a loop and delay in the code. Like for example when I drag the session to code box I get the code. now I add a loop to it and when I run it it’s fine and doesn’t get back any error but it just requests it once. even I have added loop to run it for example 4 times. I found how to add delay on running the code. I just need help to add loop to it. Thank you very much in advance.

    • Chad says:

      Hi Mohammad. I can’t reproduce your problem. In fact, I can easily add loops such as:

      private void MakeRequests()
      {
         HttpWebResponse response;
      
         for(int i=0; i<4; i++)
         {
            if (Request_www_fiddler2_com(out response))
            {
               response.Close();
            }
         }
      }

      When I run this (along with the generated "Request_www_fiddler2_com" function), I see 4 requests in the Fiddler window, just like I would expect. Can you please post the code you're trying to run, so I can further help? Thanks.

  10. Michael says:

    Hi Chad,

    I just downloaded Fiddler Request To Code 1.7.1 and noticed a couple of issues when clicking the Run (beta) button when the language is C#.

    First, I receive an compilation error indicating that the source code could not be compiled because the type or namespace ‘Stream’ could not be found.

    Second, if I add the statement using System.IO; to the top of the code window, I receive a compilation error indicating that there is an invalid token ‘using’ in class, struct, or interface member declaration.

    Third, when the code is created, if the request being converted contains a SOAPAction in the request header, when the code is created for the line below, it creates two double-quotes around the method name in that line, as follows: request.Headers.Add("SOAPAction", ""methodName"");. It should only have one double-quote before and after the method name value.

    Finally, if the request being converted contains a value of “Expect: 100-continue” in the request header, the code creates the following line, which causes an exception because the .NET Framework rejects values containing the string “100-continue” for the property being set: request.Expect = "100-continue";

    Other than these issues, the extension works nicely from what I’ve seen so far. Also, I’d be happy to fix these issues and test the modifications if you’d like to send me the source code.

    Keep up the good work!

    • Chad says:

      Hi Michael. Thanks for the bug reports. Request To Code 1.8.0 has been published and it addresses/fixes all of the issues you mentioned.

      You can read the Changelog for more information.

  11. Mazhar Karimi says:

    Awesome Job Chad, Keep it up! It works!

  12. ümit says:

    Hi Chad, this is a wonderful and very useful plugin. But i have character problems on ajax post request. Dou have any exprience about this issuse?

    • Chad says:

      Hi ümit! You’ll have to provide more information about the characters that you’re having trouble with. Can you post a sample here, or provide a link where I can try this myself? Thanks for the kinds words and I’m glad you like the extension. Thanks, ~Chad

  13. Vlado says:

    Thank you, works perfectly.

  14. Lewis says:

    Hi Chad,

    I love this extension for fiddler, I don’t suppose I could request a feature where you can execute the code request from within fiddler itself?

    Cheers,
    Lewis

    • Chad says:

      Lewis – thanks for your comment and question! I’ve added dynamic compilation in version 1.7.0 as you can read in the changelog.

      Also, have you considered just using Fiddler’s “Request Builder” if you just need to make one-off requests and change the headers/body of the request?

  15. Cathy says:

    Will Fiddler work when testing what values are being sent to a Learning Management System (LMS) outside of our company. The hdnCompletionStatus is set to Failed until they reach the passing score of 70% in which it changes to Passed. On the LMS side once it reaches the passing score of 70% the Listerner page stops. The LMS company used the Fiddler to check what data was coming back from the CBTs which they noted is 70% even though the actual score could be 80, 90 or 100%. The same CBTs works in the UAT environment documenting the correct score that was achieved.

    Questions is will Fiddle let me know what we are actually passing to the LMS which seems to be different than what the LMS is receiving or processing once they receive it. I don’t know much about a Listening page but if its stops working after it indicated that they reached the minimum passing score, how would it catch the actual end results of the missed questions.

    Any help you can provide will be greatly appreciated…the CBTs in questions were built using Captivate 4.

    Thanks Cathy

    • Chad says:

      Hi Cathy,

      This question would be better answered on the official Fiddler forums: http://groups.google.com/group/httpfiddler. This page is just about an extension I built for Fiddler.

      In general, it sounds like you want to look at the web traffic. If your web pages use HTTP to send information to the LMS, you should be able to watch it with Fiddler and see the values being sent. Just give it a try or check out the Fiddler help pages to get a better idea of how to use Fiddler: http://fiddler2.com/Fiddler/help/

      Thanks and good luck,
      ~Chad

  16. Chad says:

    @Salabim – Forgot to mention that you’ll need to call the MakeRequests() function that is generated to actually have it call of generated request methods.

    1) Drag and Drop your sessions into the “Code” view.
    2) Ensure the “Usage” option is checked.
    3) Copy all of the generated code into your Visual Studio project.
    4) In your code in VS, call MakeRequests()

  17. Chad says:

    @Steve – I think you may be mistaken. Are you able to provide a URL to test against? In my tests the request.ContentLength is being set to the proper value if there was a POST request. The extension merely copies most of the header values that I get from Fiddler. That’s why the extension writes request.ContentLength = 508; (for example) rather than always just writing request.ContentLength = postBytes.Length;. The only problem this should cause is if you want to change the request body. In that case, you would have to update the ContentLength. I’ll make the change so that it’s always set to postBytes.Length. Again, it would be great if you could also give more detail on the case you’re talking about. Thanks.

    @Salabim – The usage box generates a function that calls all of the request functions that were generated and gives you a good idea of how to use the functions. That usage box is the quickest way. You’ll want to have that option on, then copy all of the code into your Visual Studio project. If all you want is for the requests to be reissued from your code, that’s all you should need to do. If you want to actually examine the responses, you’ll need to add additional code. Hope that helps. I’ll try to add this information to the extension page so others will know. Thanks.

  18. Salabim says:

    Thank you *very* much for this fantastic add-on, it’s great !

    Just two tiny Q’s
    1) What’s the purpose of the “Usage” tickbox.
    2) How can we easily use your code afterwards to autorun the code/requests ?

  19. Steve says:

    Great little tool, saved me a bit of typing at least!

    I did see one problem, the “request.ContentLength” value was not set to the correct value. I changed the code to “request.ContentLength = postBytes.Length” and it worked fine.

  20. Great job Chad! I love it!

  21. Stefano says:

    Absolutly great. Love It!
    I’m a lucky guy to have found your program today. It saved me hours of work!
    T H A N K Y O U!

  22. Dwayne says:

    very cool. Thanks for doing this.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>