How to send multiple requests sequentially using fiddler script

4 posts, 0 answers
  1. Yi
    Yi avatar
    2 posts
    Member since:
    Mar 2015

    Posted 24 Mar 2015 Link to this post

    I know how to do this using the right click menu "Reissue Sequentially" but I'm not sure how to do same thing using fiddler script.

    For example I have two or more requests need to be generated in strict order. 

    var RequestA="POST xxxxx";
    FiddlerObject.utilIssueRequest(RequestA);           

    var RequestB="POST xxxxx";
    FiddlerObject.utilIssueRequest(RequestB);           

    I guess Fiddler will try to submit these requests in order but cannot guarantee that "later requests will be submitted only when earlier requests are finished" due to network lags.

    I googled and found something related but I'm not sure if the following can do exactly what I want. 

        var b=false;
        while(!b){
            try{
                  FiddlerObject.utilIssueRequest(s);   
                  b=true;
            }
          catch   {
          }

    Any suggestions?
        

  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 25 Mar 2015 Link to this post

    Hello, Yi--

    No, the code you found won't work any better than the code you were using before.

    The secret is to use the SendRequestAndWait function.

       var oSD = new System.Collections.Specialized.StringDictionary();
        var newSession = FiddlerApplication.oProxy.SendRequestAndWait(oSession.oRequest.headers, oSession.requestBodyBytes, oSD, null);
       if (200 == newSession.responseCode)
       {
        ....
       }


    Regards,
    Eric Lawrence
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. Yi
    Yi avatar
    2 posts
    Member since:
    Mar 2015

    Posted 25 Mar 2015 in reply to Eric Lawrence Link to this post

    Hi Eric,

    Thanks a lot for your helpful reply!

    I searched SendRequestAndWait() but can only found limited discussions so I am still a bit confused. 

    This is an example of my old way to fully customize a request using fiddler script.

    var Header = "User-Agent: XXXXX";    //so I can test with different settings like different browsers, different encoding etc. 
    var Content = "id=1&token=XXXX";
    var Request = "POST https://www.example.com/download.php HTTP/1.1\r\n" + Header + "Content-Length: " + Content.length + "\r\n\r\n" + Content;

    FiddlerObject.utilIssueRequest(Request);           

    I know this doesn't look very beautiful but it did work well. 

    How can I merge this type of request with SendRequestAndWait() function? Could you please provide a simple example?

    -Best

    Yi













  4. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 26 Mar 2015 Link to this post

    Hi, Yi--

    SendRequestAndWait accepts a set of headers and a body and it sends the specified request, blocking until the request is sent. The code sample I provided below shows you how to use this.

    If you're saying: "I don't know how to use a headers object instead of a string", that's pretty simple:

      var Content: byte[] = System.Text.Encoding.UTF8.GetBytes("id=1&token=XXX");
      var oRQH: HTTPRequestHeaders = new HTTPRequestHeaders("/download.php", ['Host: www.example.com','Content-Length: '+Content.length.ToString(), 'Content-Type: application/x-www-url-encoded']);
      oRQH.HTTPMethod = "POST";
      var oSD = new System.Collections.Specialized.StringDictionary();
        var newSession = FiddlerApplication.oProxy.SendRequestAndWait(oRQH, Content, oSD, null);

       if (200 == newSession.responseCode)
       {
    //...
       }



    Regards,
    Eric Lawrence
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top