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.2.1.0, 75.39 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.

58 Responses to Fiddler Extension – Request to Code

  1. Bill Sambrone says:

    This is a really handy extension. Too bad I discovered it AFTER writing a series of requests in C# first! I’ll be sure to use this often in the future. Thank you very much for putting it together.

  2. Trev says:

    Any chance of adding in Javascript/jQuery? Seems Microsoft is pushing us all there at the moment.

    • Chad says:

      Hi Trev. Thanks for the suggestion. I assume – so correct me if I’m not following – but you mean you’d like to see JS (possibly using jQuery) that would make an equivalent AJAX call?

  3. Mustafa says:

    I am interested in capturing the tunnel requests ? How can I do that ???

    • Chad says:

      What are you hoping to accomplish by getting code for the CONNECT tunnels?

      By design, the extension does not generate code to duplicate the CONNECT tunnels. This is because all of the generated code automatically will tunnel/CONNECT as needed. For instance, the HttpWebRequest that’s used in the .NET languages automatically does a CONNECT when you use it to go to a HTTPS URL. Thanks, ~Chad

  4. Ryan Russon says:

    Fantastic work! Your extension has been a huge time-saver for me. Thanks!!! About the only thing I find I must modify to make a lot of the generated scripts (C#) work is defining a global CookieContainer variable and assigning it to the CookieContainer of every request so that all cookies are martialled correctly.

    • Chad says:

      Hi Ryan. You’re not alone! Others have also asked for cookie handling. I plan to add something and what you’re doing sounds about right. Thanks! ~Chad

  5. Robert Innes says:

    Chad,
    Your product rocks and has helped solve several issues.
    Thank You very much for your time and effort.
    I have a suggestion, would it be possible for you to allow the generation of code compatible to drop into linqpad. I can do that now, by stripping off the parts that are not needed, but it would be nice to have a cut and paste option. Just being lazy :-)

    - Bob

  6. Nick says:

    Hello Chad! I just wanted to take the time to say thank you for this awesome extension! Being somewhat new to coding, I was beginning to become very frustrated with HTTP related development. Whether it involved the headers, postData or cookies, I always seemed to get bad responses. Thanks to your extension, however, I have had something to reference within my programming language, and it has enabled me to build a steady understanding of it all. So again, thank you for taking the time write this nifty plugin, and I give you a nod for releasing it for free. Thanks again!

    • Chad says:

      Thanks so much for the kind words. I’m happy to hear it has helped you get a better grasp on HTTP! I know I gained a lot of understanding developing the extension and handling a lot of the corner cases. HTTP is very important to understand, regardless of whatever other languages you develop with. Cheers! ~Chad

  7. Tesla says:

    Hi , Chad . Its amazing :)

    Lifesaver.

  8. Dimm says:

    Hi Chad,
    This is very cool indeed!
    1 small bug: method names are truncated Generatecode becomes …._nerateForm, ….._receive becomes …._eceive , ….._downloadzip becomes …..oadzip.
    1 suggestion: is it possible to handle cookies better? Maybe check if cookes are returned, add them to a collection and send the dynamic values on subsequent requests, instead of hardcoding them in the header?

    • Chad says:

      Hi Dimm. Thanks for mentioning the function name generation. I can reproduce what you’re saying, but this is actually by design so that function names do not get too long. If necessary, the function name generation trims the “filename” portion of the URL to the *final* 10 characters. This is so that you can see the file extension. There might be more graceful ways to handle it besides just increasing the limit or showing just the first 10 characters, so I’m open to suggestions.

      Also, thanks for your suggestion about preserving cookies between subsequent requests based on the previous response. I’ve had a number of requests to improve cookie handling, so I may look into this. It’s just a matter of how much it would complicate the generated code as well as how this would be enabled or disabled in the UI, as space is at a premium. Again, suggestions are welcome.

      Thanks,
      ~Chad

  9. Piotr says:

    Hello!
    Firstly I would like to thank you for the great extension!
    It works great, even the multipart-b req are working fine.
    But in my opionion it would be cool if u could add option to automatically decode the response body. I mean :

    using (var httpWebResponse = imgrequest.GetResponse() as HttpWebResponse)
    {
    Stream stream = null;
    using (stream = httpWebResponse.GetResponseStream())
    {
    if (httpWebResponse.ContentEncoding.ToLower().Contains(“gzip”))
    stream = new GZipStream(stream, CompressionMode.Decompress);
    else if (httpWebResponse.ContentEncoding.ToLower().Contains(“deflate”))
    stream = new DeflateStream(stream, CompressionMode.Decompress);

    var streamReader = new StreamReader(stream, Encoding.UTF8);
    strResponse = streamReader.ReadToEnd() ;
    }
    }

    What do you think about it ?
    Regards,
    Piotr

    • Chad says:

      Hi Piotr. Thanks for the good idea. I will look into this and likely add it in the next release. It would probably be another optional check like the “Comments” and “Usage” so that it doesn’t always bulk up the generated code. Thanks for your suggestion!

    • Chad says:

      Hi Piotr. Request to Code version 2.2.0.0 has just been released and adds support for response reading. Thank you again for your suggestion. ~Chad

  10. Ivar says:

    Nice plugin. Could be very useful, but I have one slight problem with it. When the request contains headers with quotes the resulting c# code is invalid. Example:

    request.Headers.Set(HttpRequestHeader.Authorization, “Digest realm=”Digest Authentication”, nonce=”nonce”, opaque=”opaque”, stale=”false”, algorithm=”MD5″, qop=”auth”, response=”51666f8aaef4d9eb290d441cf00b156c”, uri=”http://localhost.fiddler:63990/1/api/calls/4d148495-1310-4b89-b2c8-4d0c6cc90073/entries”, username=”ivar””);

    • Chad says:

      Thanks! While most all headers were properly being set and escaped if needed, the HTTP Authorization header was not. This will be fixed in an upcoming release that you can expect within the next week.

  11. Crashouille says:

    Is it possible to contribute to the plugin i.e. is it open source ?

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>