Save Response

5 posts, 0 answers
  1. Avinash
    Avinash avatar
    10 posts
    Member since:
    Jan 2015

    Posted 29 Jan 2015 Link to this post

    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.

















  2. Avinash
    Avinash avatar
    10 posts
    Member since:
    Jan 2015

    Posted 29 Jan 2015 Link to this post


         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));
  3. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 29 Jan 2015 Link to this post

    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.

     
  4. Avinash
    Avinash avatar
    10 posts
    Member since:
    Jan 2015

    Posted 30 Jan 2015 in reply to Eric Lawrence Link to this post

    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.



     
  5. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 30 Jan 2015 Link to this post

    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.

     
Back to Top