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

How to send multiple requests sequentially using fiddler script

3 Answers 1542 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Yi
Top achievements
Rank 1
Yi asked on 25 Mar 2015, 02:59 AM
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?
    

3 Answers, 1 is accepted

Sort by
0
Eric Lawrence
Telerik team
answered on 25 Mar 2015, 01:16 PM
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.

 
0
Yi
Top achievements
Rank 1
answered on 25 Mar 2015, 02:10 PM
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













0
Eric Lawrence
Telerik team
answered on 26 Mar 2015, 07:38 PM
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.

 
Tags
Fiddler Classic
Asked by
Yi
Top achievements
Rank 1
Answers by
Eric Lawrence
Telerik team
Yi
Top achievements
Rank 1
Share this question
or