Parsing out POST Form data in before transmit POST

4 posts, 1 answers
  1. Dr DB
    Dr DB avatar
    2 posts
    Member since:
    Mar 2015

    Posted 11 Jun 2015 Link to this post

    Dear FiddlerCore people:

    I would like to capture the Http POST stream to the server to extract the FORM and Cookie data.

    I would like to only have a proxy for the current proc. This code sets the proxy for all the browsers, and

    breaks the internet on proxy using browsers while I'm working on this. I'm only interested in one particular

    windows forms browser http call. I can capture the cookies from the forms browser  but not the FORM in the

    header. So I have to capture the call data with Fiddler. Once I have the data from the client prepared for the server,

    I want to CANCEL the call and abort the forms browser call and do a HTTPWebRequest using the cookies and FORMS data.

     

    A session is the http web request and response?

     

    I'm only interested in the request and I will edit the request and send a HTTP web request with the environment

    of the forms browser.

     

    My problem is that the website code spawns a new browser outside the thread I control in the form web browser.

    I want to intercept the call and either edit it so it does not spawn a new client thread, or send the request in http webRequest and webResponse.

    I'm looking at the oS data structure and starting to see what it contains. 

     What is the best way to edit this and cancel the current request in the session?

     

     

     

              Fiddler.URLMonInterop . SetProxyInProcess ( "127.0.0.1:8888" , "<-loopback>" );
                Fiddler . FiddlerApplication . Startup ( 8888 , false , false );
                //Fiddler . FiddlerApplication . Startup ( 0 , FiddlerCoreStartupFlags . Default );

                 Fiddler . FiddlerApplication . BeforeRequest += delegate ( Fiddler . Session oS )
                    {
                    Debug . WriteLine ( "Before request for:\t" + oS . fullUrl );
                    Debug . WriteLine ( String . Format ( "{0}:{1} >>{2}<<" , oS . id , oS . PathAndQuery, oS.RequestHeaders, oS.RequestMethod ,oS.RequestBody.ToString() ) );
                    string code;
                    List<Fiddler.Session> oAllSessions = new List<Fiddler . Session> ( );
                    oS . bBufferResponse = true;
                    Monitor . Enter ( oAllSessions );
                    oAllSessions . Add ( oS );
                    Monitor . Exit ( oAllSessions );
                    };


  2. Answer
    Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 15 Jun 2015 Link to this post

    Hello, DB--

    You have quite a few questions here.

    > A session is the http web request and response?

    Yes. The Session has both a request and response object (oRequest, oResponse)

    > My problem is that the website code spawns a new browser outside the
    > thread I control in the form web browser.

    How, specifically, does it spawn such a browser? Does it use JavaScript with window.open or the like? If you're hosting the .NET Web Browser control, you can have the popups occur within your application instead of a desktop IE instance; see http://blogs.msdn.com/b/ieinternals/archive/2009/06/20/making-the-web-browser-control-launch-the-default-browser.aspx

    >I would like to only have a proxy for the current proc.


    Sure, the way to do that is using the SetProxyInProcess method, and ensuring you don't have the FiddlerCoreStartupFlags.RegisterAsSystemProxy flag set when you call the Startup method.

    >breaks the internet on proxy using browsers while I'm working on this


    If your code is written correctly, it won't "break the internet".

    > What is the best way to edit this and cancel the current request in the session?

    You can use the utilCreateResponseAndBypassServer method (or the oRequest.FailSession) method to return a response to the client without sending a request to the server.

    >do a HTTPWebRequest using the cookies and FORMS data.

    Why do you want to use a HTTPWebRequest at all? Fiddler's objects are perfectly capable of receiving, modifying, and sending a HTTP request without using any external classes.

    Note, the BeforeRequest method you have below is pretty buggy-- it's creating a new Session list and mutex on every single HTTP(S) request sent. You should probably start with the demo project that ships with FiddlerCore (http://www.telerik.com/fiddler/fiddlercore) and work from there.







    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Dr DB
    Dr DB avatar
    2 posts
    Member since:
    Mar 2015

    Posted 15 Jun 2015 in reply to Eric Lawrence Link to this post

    Thanks Eric!

    I'm having a log of fun learning how to use this.

    It is well thought out and very intuitive, even at the FiddlerCore level.

    A pleasure to learn. 

     

    I will tinker with what you wrote  and see if I can inline edit the send buffer.

    I prefer not to get involved with the client browser java.  

    Best would be to edit the POST so the response returns in the same thread.  

    I don't know (perhaps you do?) how to walk the java in the .NET browser when invoked('click') call from Visual Studio?

    I can walk the c# code in ASP.NET but I am woefully and willfully ignorant of java.

    Can we edit the java in the send buffer then execute back in the local .NET browser?

    I can do that in the Firefox Developer browser but not c#.

    More questions as I continue to confound myself.

    Thank you for your reply.

     

    Dr. K

     

  4. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 15 Jun 2015 Link to this post

    You may want to ask general programming questions on StackOverflow.com, as that is a better place for questions not related specifically to Fiddler and FiddlerCore.

    I think you're talking about JavaScript rather than Java, right? Visual Studio does allow you to attach its debugger to SCRIPT as well as MANAGED code; there's an option somewhere for that. You may need to unset the Internet Explorer checkbox Tools > Internet Options > Advanced > Disable Script Debugging (other).

    Fiddler allows you to rewrite the JavaScript (or HTML, CSS, etc) returned by the server; have a look at the GetResponseBodyAsString() method you can call inside your BeforeResponse handler.


    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top