Request To Code & FiddlerCore

You can use both the FiddlerCoreRequestToCode.dll and theĀ FiddlerCore library in your project to automatically generate code and do whatever you want with it. For instance, you could write a code file for each session you observe. For example:

- Reference FiddlerCoreRequestToCode.dll
- Reference FiddlerCore - http://fiddler2.com/Fiddler/Core/

************************************************************
using System.IO;
using System.Net;
using Fiddler;
using FiddlerCoreRequestToCode;
...
...
...
private void RecordCodeForUrl()
{
	//Start Fiddler on an available port
	FiddlerApplication.Startup(6575, FiddlerCoreStartupFlags.Default);

	var codeGenerator = new CodeGenerator(new CSharpLanguage()) { ShowUsage = true, ShowComments = true };

	//For each request...
	FiddlerApplication.BeforeRequest += (session) =>
	{
		string code;
		if (codeGenerator.TryGenerateCode(new[] { session }, out code))
		{
			//You'll need to make the file path unique
			File.WriteAllText(Environment.CurrentDirectory + "/" + "request.cs", code);
		}
	};

	//You'll probably have another way of creating the traffic to be recorded.
	//This is just an example.
	var request = WebRequest.Create("http://fiddler2.com/fiddler2/");
	var response = request.GetResponse();
	using (var reader = new StreamReader(response.GetResponseStream()))
	{
		string html = reader.ReadToEnd();
	}
	response.Close();

	//Stop Fiddler.
	FiddlerApplication.Shutdown();
}

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>