This is a migrated thread and some comments may be shown as answers.

Save Response

4 Answers 190 Views
FiddlerCore
This is a migrated thread and some comments may be shown as answers.
Avinash
Top achievements
Rank 1
Avinash asked on 29 Jan 2015, 11:41 AM
Hi Eric,

          I have created sample app(Console App in c#) with Selenium Webdriver and BrowserMob Proxy. BrowserMob Proxy has method which return response,i'm write response to a file as follow using below code
               Server server = new Server(<proxy path>);
                server.Start();
                Client client = server.CreateProxy();
                client.NewHar("google");
                var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };                
                var profile = new FirefoxProfile();
                profile.SetProxyPreferences(seleniumProxy);
                IWebDriver driver = new FirefoxDriver(profile);  
               driver.Navigate().GoToUrl(<url>);
              // below harData has response
               HarResult harData = client.GetHar();
               System.IO.File.WriteAllText(<file path>, JsonConvert.SerializeObject(harData, Formatting.Indented));


              Is it possible to do same thing with Selenium Webdriver and Fiddler.

Thanks,
Avinash.

















4 Answers, 1 is accepted

Sort by
0
Avinash
Top achievements
Rank 1
answered on 29 Jan 2015, 12:48 PM

     found below code by exploring session object,is there any other way to write response.
         var response =  session.oResponse;
         System.IO.File.WriteAllText(<file path>, JsonConvert.SerializeObject(response, Formatting.Indented));
0
Eric Lawrence
Telerik team
answered on 29 Jan 2015, 06:49 PM
I'm not entirely sure what you're asking. Are you using Fiddler, or FiddlerCore?

Either way, Fiddler exposes many different ways to export data from a given session, depending on whether you want to include headers, only the body bytes, whether you'd like the body to be unchunked and decompressed, etc.

The simplest thing you can do is:

  oSession.utilDecodeResponse(); // Remove chunking/compression
  oSession.SaveResponseBody("C:\\temp\\whatever.dat");

... but there are many other approaches depending on what exactly it is you're trying to accomplish.


Regards,
Eric Lawrence
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Avinash
Top achievements
Rank 1
answered on 30 Jan 2015, 07:44 AM
Hi Eric,
    i am newbie to FiddlerCore.Response not decoded with session.utilDecodeResponse()

FiddlerCoreStartupFlags flags = FiddlerCoreStartupFlags.DecryptSSL & FiddlerCoreStartupFlags.AllowRemoteClients & FiddlerCoreStartupFlags.CaptureFTP & FiddlerCoreStartupFlags.ChainToUpstreamGateway & FiddlerCoreStartupFlags.MonitorAllConnections & FiddlerCoreStartupFlags.CaptureLocalhostTraffic;

 FiddlerApplication.Startup(9876, flags);        
          FiddlerApplication.AfterSessionComplete += SaveResponse;
          OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
          proxy.HttpProxy = string.Format("127.0.0.1:{0}", 9876);
          FirefoxProfile profile = new FirefoxProfile();
          profile.SetProxyPreferences(proxy);
          IWebDriver driver = new FirefoxDriver(profile);
          driver.Navigate().GoToUrl(@"https://www.google.com");
          
          driver.Quit();
          FiddlerApplication.Shutdown();
       
 saveResponse(session targersession)
 {
 var response = targetSession.oResponse;
            var decodedSuccessfully= targetSession.utilDecodeResponse();
       //getting decodedSuccessfully as false;
             Console.WriteLine("Decode {0}",decodedSuccessfully.ToString());
            
            targetSession.SaveResponseBody(@"E:\Response.dat");
             
}

could you suggest me a solution for decoding response

Thanks,
Avinash.



 
0
Eric Lawrence
Telerik team
answered on 30 Jan 2015, 03:31 PM
1. If you use a fixed filename like this, every single response will try to write to the same file and you will get file-in-use (locking) errors or corrupt files (due to multi-threading).
2. Did you examine your "response.dat" file?
3. utilDecodeResponse() returns false if the content isn't compressed or chunked.


Regards,
Eric Lawrence
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
FiddlerCore
Asked by
Avinash
Top achievements
Rank 1
Answers by
Avinash
Top achievements
Rank 1
Eric Lawrence
Telerik team
Share this question
or