Save Request/Response to C# Function?

924 views
Skip to first unread message

Chad Sowald

unread,
Jan 19, 2010, 11:39:58 AM1/19/10
to Fiddler
Hi Eric. I was wondering if there is a way in Fiddler to save a
request in Fiddler to a C# function much like you can save it to a
webtest...or if Fiddler could just have another tab under the request
builder (e.g. "C#") that would just have the text of the function that
the user could copy? So, I would copy the function and then call it.
It would, out of the box, simply return true/false depending on if a
response came back and would use the standard .NET framework.

Does it already do this or is this a possible future feature? Thanks.

EricLaw

unread,
Jan 19, 2010, 1:03:53 PM1/19/10
to Fiddler
It's an interesting idea. The only trouble is that there are *some*
requests that cannot be generated using the standard .NET classes; for
instance, you cannot set some of the headers using C#.

But you could pretty easily write an extension or a bit of script that
would get you most of the way there. It would create a webrequest
object, set the URL, and add headers (as possible) to the object.
You'd obviously have to test it to prevent it from throwing exceptions
if you try to set a restricted header.

Chad Sowald

unread,
Jan 21, 2010, 4:37:50 PM1/21/10
to Fiddler
Hey Eric. I thought I might just give it a try and create my own
extension. A couple questions that I couldn't find answers to in the
extension docs...

1) How do I add a tab inside of the Request Builder tab page? I found
FiddlerApplication.UI.pageBuilder, which I think is the Request
Builder page, but I'm not sure how to add my custom tab to it.
2) How do I get notified when a user drags & drops a session into the
Request Builder tab page and get that session to work with it in the
event handler?

Thanks ~Chad

EricLaw

unread,
Jan 21, 2010, 5:08:41 PM1/21/10
to Fiddler
The RequestBuilder's tabs aren't public and thus you cannot add
directly to them. Your best bet is to add a new View tab (e.g. like
Statistics, Inspectors, RequestBuilder, etc) that is specific to your
extension.

To add a tab, you'll want to use code like this:

// http://www.fiddler2.com/fiddler/dev/IFiddlerExtension.asp
public void OnLoad()
{
oPage = new TabPage("Timeline");
oPage.ImageIndex = (int)Fiddler.SessionIcons.Timeline;
oView = new TimelineView();
oPage.Controls.Add(oView);
oView.Dock = DockStyle.Fill;
FiddlerApplication.UI.tabsViews.TabPages.Add(oPage);
}

And then to allow dropping of sessions, you'll want to do something
like this:

void oPage_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("Fiddler.Session[]"))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}

void oPage_DragDrop(object sender, DragEventArgs e)
{
Session[] oSessions = (Session[])e.Data.GetData
("Fiddler.Session[]");
if ((oSessions == null) || (oSessions.Length < 1))
{ Debug.Assert(false, "Unexpected drop type."); return; }
}

> > > Does it already do this or is this a possible future feature?  Thanks.- Hide quoted text -
>
> - Show quoted text -

Chad Sowald

unread,
Jan 21, 2010, 6:15:53 PM1/21/10
to Fiddler
Thanks so much for the code/info. I had seen the tab add code, but
was hoping there was a way to add to the Request Builder tab itself.
In any case, that's not all that important.

The Drag & Drop code worked like a charm and I've been able to access
the session's request.

Now I just need to take care of templating the request code and
polishing the UI. Thanks for your help, Eric!


On Jan 21, 5:08 pm, EricLaw <bay...@gmail.com> wrote:
> The RequestBuilder's tabs aren't public and thus you cannot add
> directly to them. Your best bet is to add a new View tab (e.g. like
> Statistics, Inspectors, RequestBuilder, etc) that is specific to your
> extension.
>
> To add a tab, you'll want to use code like this:
>

> //http://www.fiddler2.com/fiddler/dev/IFiddlerExtension.asp

Chad Sowald

unread,
Jan 28, 2010, 5:11:32 PM1/28/10
to Fiddler
Hi Eric. I'm nearly done with the extension, but I'm not sure how to
handle the Fiddler DO NOT TRUST certificate. For instance....if the
user codifies an HTTPS request, then when they make the request by
running their own program AND FIDDLER IS RUNNING the request will fail
if the user does not already trust the Fiddler DO NOT TRUST
certificate, which is the expected behavior. However, I'm not sure if
I should add some additional code to install the certificate or if
users should just be aware that running HTTPS requests
programmatically while Fiddler is running will fail? What would be
the best course of action?

Thanks,
~Chad

EricLaw

unread,
Jan 28, 2010, 6:07:21 PM1/28/10
to Fiddler
Well, you could write the code that implements the
CertificateValidationCallback method:
http://msdn.microsoft.com/en-us/library/dd633677%28EXCHG.80%29.aspx

But generally speaking, if someone is going to the trouble of
exporting traffic from Fiddler to a .NET program, I think that's a
good sign that they expect to be running their client without Fiddler
running.

> > > > - Show quoted text -- Hide quoted text -

Chad Sowald

unread,
Jan 29, 2010, 10:37:35 PM1/29/10
to Fiddler
Hey Eric. Well, I just posted the link -
http://groups.google.com/group/httpfiddler/browse_thread/thread/4a80fc68e605dedc
- on this boards to the first version of this extension. I decided to
not bother handling the DO NOT TRUST certificate. Thanks for your
help and let me know if you have any requests/suggestions about it.
~Chad
Reply all
Reply to author
Forward
0 new messages