Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Fiddler Web Debugger - Importing and Exported from Fiddler with .NET Code
Get Fiddler!
Addons
Discuss
Contact
Introduction
Fiddle r 2.2.9.5 introduce d the ISe ssionIm port and ISe ssionEx port inte rface s, allowing you to im port traffic to Fiddle r and e x port it to othe r file form ats. Fiddle r ships with a num be r of the se "transcode rs" by de fault, but you can also write your own using any .NET language .
Prerequisites
Fiddle r v2.x loads only .NET CLR v2.0 asse m blie s; use Visual Studio 2005+ to com pile your e x te nsion. If you use Visual Studio 2010 or late r, you must change your proje ct to targe t the .NET2.0/3.5 fram e work or Fiddle r will not load your e x te nsion. Fiddle r itse lf re quire s only that the use r have .NET Framework 2.0 SP1 installe d. You may have your e x te nsions targe t the .NET Fram e work 3.5 (which include s Linq) since that fram e work also (confusingly) runs on the v2.0 C LR but you MUST yourse lf e nsure that the use r has the re quire d Fram e work ve rsion installe d BEFO R E you install your e x te nsion, or a use r with only the olde r Fram e work will crash on boot. You should also e nsure your proje ct targe ts A nyCPU to e nsure that it work s prope rly with 64bit Fiddle r. Le arn m ore about Building asse m blie s to run in both Fiddle r v2 and v4
http://fiddlerbook.com/Fiddler/dev/ISessionExport.asp
1/7
3/25/2014
Fiddler Web Debugger - Importing and Exported from Fiddler with .NET Code
Se t the F i d d l e r . R e q u i r e d V e r s i o n attribute in your A s s e m b l y I n f o . c s file (or e lse whe re in your code ), as follows:
u s i n gF i d d l e r ; / /T h i sT r a n s c o d e rr e q u i r e sF i d d l e r2 . 2 . 9 . 7 +b e c a u s et h a ti sw h e nt h e / /I S e s s i o n I m p o r ta n dI S e s s i o n E x p o r ti n t e r f a c e sw e r ef i n a l i z e d . [ a s s e m b l y :F i d d l e r . R e q u i r e d V e r s i o n ( " 2 . 2 . 9 . 7 " ) ] If Fiddle r finds a R e q u i r e d V e r s i o nattribute that indicate s a late r ve rsion of Fiddle r is re quire d, the use r will be notifie d that a late r ve rsion of Fiddle r is re quire d to use your e x te nsion. Asse m blie s which do not contain a R e q u i r e d V e r s i o nattribute are sile ntly ignore d.
p u b l i ci n t e r f a c eI S e s s i o n I m p o r t e r:I D i s p o s a b l e
S e s s i o n [ ]I m p o r t S e s s i o n s ( s t r i n gs I m p o r t F o r m a t ,D i c t i o n a r y < s t r i n g ,
o b j e c t >
d i c t O p t i o n s ,
E v e n t H a n d l e r < P r o g r e s s C a l l b a c k E v e n t A r g s >e v t P r o g r e s s N o t i f i c a t i o n s ) ; } The m e thod should re turn an array of Se ssion obje cts cre ate d from the Im port of the data. The dictO ptions dictionary m ay be null, or m ay contain a se t of string-k e ye d obje cts. Most im porte rs support spe cification of a file nam e lik e so d i c t O p t i o n s [ " F i l e n a m e " ]=" C : \ \ t e s t . f i l e "
p u b l i ci n t e r f a c eI S e s s i o n E x p o r t e r:I D i s p o s a b l e
b o o lE x p o r t S e s s i o n s ( s t r i n gs E x p o r t F o r m a t ,S e s s i o n [ ]o S e s s i o n s ,
D i c t i o n a r y < s t r i n g ,o b j e c t >d i c t O p t i o n s ,
E v e n t H a n d l e r < P r o g r e s s C a l l b a c k E v e n t A r g s >e v t P r o g r e s s N o t i f i c a t i o n s ) ; } The m e thod should re turn True if the e x port of the se ssions passe d via the oSe ssions param e te r is succe ssful. The dictO ptions dictionary m ay be null, or m ay contain a se t of string-k e ye d obje cts. Most im porte rs support spe cification of a file nam e lik e so d i c t O p t i o n s [ " F i l e n a m e " ]=" C : \ \ t e s t . f i l e "
3/25/2014
Fiddler Web Debugger - Importing and Exported from Fiddler with .NET Code
If the C ance l flag is se t on the Progre ssC allback Eve ntArgs obje ct afte r be ing passe d to the e v t P r o g r e s s N o t i f i c a t i o n scallback , im port or e x port should grace fully te rm inate as soon as possible .
[ P r o f f e r F o r m a t ( " T A B S e p a r a t e dV a l u e s " ," S e s s i o nL i s ti nT a b D e l i m i t e d F o r m a t " ) ] [ P r o f f e r F o r m a t ( " C o m m a S e p a r a t e dV a l u e s " , " S e s s i o nL i s ti nC o m m a D e l i m i t e dF o r m a t ;i m p o r ti n t oE x c e lo ro t h e r t o o l s " ) ] p u b l i cc l a s sC S V T r a n s c o d e r :I S e s s i o n E x p o r t e r / /E n s u r ec l a s si sp u b l i c ,o r F i d d l e rw o n ' ts e ei t ! { p u b l i cb o o lE x p o r t S e s s i o n s ( s t r i n gs F o r m a t ,S e s s i o n [ ]o S e s s i o n s , D i c t i o n a r y < s t r i n g ,o b j e c t >d i c t O p t i o n s , E v e n t H a n d l e r < P r o g r e s s C a l l b a c k E v e n t A r g s >e v t P r o g r e s s N o t i f i c a t i o n s ) { b o o lb R e s u l t=f a l s e ; s t r i n gc h S p l i t ;
http://fiddlerbook.com/Fiddler/dev/ISessionExport.asp 3/7
3/25/2014
Fiddler Web Debugger - Importing and Exported from Fiddler with .NET Code
/ /D e t e r m i n ei fw ea l r e a d yh a v eaf i l e n a m ef r o mt h ed i c t O p t i o n s c o l l e c t i o n s t r i n gs F i l e n a m e=n u l l ; i f( n u l l! =d i c t O p t i o n s& &d i c t O p t i o n s . C o n t a i n s K e y ( " F i l e n a m e " ) ) { s F i l e n a m e=d i c t O p t i o n s [ " F i l e n a m e " ]a ss t r i n g ; } i f( s F o r m a t= =" C o m m a S e p a r a t e dV a l u e s " ) { c h S p l i t=" , " ; i f( s t r i n g . I s N u l l O r E m p t y ( s F i l e n a m e ) )s F i l e n a m e= F i d d l e r . U t i l i t i e s . O b t a i n S a v e F i l e n a m e ( " E x p o r tA s"+s F o r m a t ," C S VF i l e s ( * . c s v ) | * . c s v " ) ; } e l s e { c h S p l i t=" \ t " ; i f( s t r i n g . I s N u l l O r E m p t y ( s F i l e n a m e ) )s F i l e n a m e= F i d d l e r . U t i l i t i e s . O b t a i n S a v e F i l e n a m e ( " E x p o r tA s"+s F o r m a t ," T S VF i l e s ( * . t s v ) | * . t s v " ) ; } i f( S t r i n g . I s N u l l O r E m p t y ( s F i l e n a m e ) )r e t u r nf a l s e ; t r y { S t r e a m W r i t e rs w O u t p u t=n e wS t r e a m W r i t e r ( s F i l e n a m e ,f a l s e , E n c o d i n g . U T F 8 ) ; i n ti C o u n t=0 ; i n ti M a x=o S e s s i o n s . L e n g t h ; # r e g i o nW r i t e C o l H e a d e r s b o o lb F i r s t C o l=t r u e ; f o r e a c h( C o l u m n H e a d e ro L V C o li n F i d d l e r A p p l i c a t i o n . U I . l v S e s s i o n s . C o l u m n s ) { i f( ! b F i r s t C o l ) { s w O u t p u t . W r i t e ( c h S p l i t ) ; } e l s e { b F i r s t C o l=f a l s e ; } s w O u t p u t . W r i t e ( o L V C o l . T e x t . R e p l a c e ( c h S p l i t ," " ) ) ; } s w O u t p u t . W r i t e L i n e ( ) ; # e n d r e g i o nW r i t e C o l H e a d e r s # r e g i o nW r i t e E a c h S e s s i o n f o r e a c h( S e s s i o no Si no S e s s i o n s ) { i C o u n t + + ; i f( n u l l! =o S . V i e w I t e m ) { b F i r s t C o l=t r u e ;
http://fiddlerbook.com/Fiddler/dev/ISessionExport.asp 4/7
3/25/2014
Fiddler Web Debugger - Importing and Exported from Fiddler with .NET Code
L i s t V i e w I t e mo L V I=( o S . V i e w I t e ma sL i s t V i e w I t e m ) ; i f( n u l l= =o L V I )c o n t i n u e ; f o r e a c h( L i s t V i e w I t e m . L i s t V i e w S u b I t e mo L V Ci no L V I . S u b I t e m s ) { i f( ! b F i r s t C o l ) { s w O u t p u t . W r i t e ( c h S p l i t ) ; } e l s e { b F i r s t C o l=f a l s e ; } s w O u t p u t . W r i t e ( o L V C . T e x t . R e p l a c e ( c h S p l i t ," " ) ) ; } s w O u t p u t . W r i t e L i n e ( ) ; } i f( n u l l! =e v t P r o g r e s s N o t i f i c a t i o n s ) { e v t P r o g r e s s N o t i f i c a t i o n s ( n u l l ,n e wP r o g r e s s C a l l b a c k E v e n t A r g s ( ,) ) ; P r o g r e s s C a l l b a c k E v e n t A r g sP C E A=n e w P r o g r e s s C a l l b a c k E v e n t A r g s ( ( i C o u n t / ( f l o a t ) i M a x ) ," w r o t e"+i C o u n t . T o S t r i n g ( ) +"r e c o r d s . " ) ; e v t P r o g r e s s N o t i f i c a t i o n s ( n u l l ,P C E A ) ; i f( P C E A . C a n c e l ){s w O u t p u t . C l o s e ( ) ;r e t u r nf a l s e ;} } } # e n d r e g i o nW r i t e E a c h S e s s i o n s w O u t p u t . C l o s e ( ) ; b R e s u l t=t r u e ; } c a t c h( E x c e p t i o ne X ) { M e s s a g e B o x . S h o w ( e X . M e s s a g e ," F a i l e dt oe x p o r t " ) ; b R e s u l t=f a l s e ; } } r e t u r nb R e s u l t ; } p u b l i cv o i dD i s p o s e ( ) { } }
3/25/2014
Fiddler Web Debugger - Importing and Exported from Fiddler with .NET Code
v a ro E x p o r t O p t i o n s=F i d d l e r O b j e c t . c r e a t e D i c t i o n a r y ( ) ; o E x p o r t O p t i o n s . A d d ( " F i l e n a m e " ," C : \ \ u s e r s \ \ e r i c l a w \ \ d e s k t o p \ \ o u t 1 . h a r " ) ; o E x p o r t O p t i o n s . A d d ( " M a x T e x t B o d y L e n g t h " ,1 0 2 4 ) ; o E x p o r t O p t i o n s . A d d ( " M a x B i n a r y B o d y L e n g t h " ,1 6 3 8 4 ) ; F i d d l e r A p p l i c a t i o n . D o E x p o r t ( " H T T P A r c h i v ev 1 . 2 " ,o S e s s i o n s ,o E x p o r t O p t i o n s , n u l l ) ; Your Transcoder extension may collect these options like so: p u b l i cb o o lE x p o r t S e s s i o n s ( s t r i n gs F o r m a t ,S e s s i o n [ ]o S e s s i o n s , D i c t i o n a r y < s t r i n g ,o b j e c t >d i c t O p t i o n s , E v e n t H a n d l e r < P r o g r e s s C a l l b a c k E v e n t A r g s >e v t P r o g r e s s N o t i f i c a t i o n s ) { / / . . . i f( n u l l! =d i c t O p t i o n s ) { i f( d i c t O p t i o n s . C o n t a i n s K e y ( " F i l e n a m e " ) ) { s F i l e n a m e=d i c t O p t i o n s [ " F i l e n a m e " ]a ss t r i n g ; } i f( d i c t O p t i o n s . C o n t a i n s K e y ( " M a x T e x t B o d y L e n g t h " ) ) { i M a x T e x t B o d y L e n g t h=( i n t ) d i c t O p t i o n s [ " M a x T e x t B o d y L e n g t h " ] ; } i f( d i c t O p t i o n s . C o n t a i n s K e y ( " M a x B i n a r y B o d y L e n g t h " ) ) { i M a x B i n a r y B o d y L e n g t h=( i n t ) d i c t O p t i o n s [ " M a x B i n a r y B o d y L e n g t h " ] ; } } Almost done... Compile your project. Drop your assembly .DLL in your \Documents\Fiddler2\ImportExport\ folder (or use \Program Files\Fiddler2\ImportExport\to make available to all users on the machine) Restart Fiddler2. Click File > Import or File > Export If you need help or have questions, please email me using the Contact link above.
Change Log 6/21/10 - Created 6/28/10 - Updated with Cancel flag 6/29/10 - Updated Interface signatures with dictOptions collection introduced in Fiddler 2.2.9.7 4/04/11 - Updated with additional information about passing parameters via Options dictionary
2013 Telerik
http://fiddlerbook.com/Fiddler/dev/ISessionExport.asp
6/7
3/25/2014
Fiddler Web Debugger - Importing and Exported from Fiddler with .NET Code
http://fiddlerbook.com/Fiddler/dev/ISessionExport.asp
7/7