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

How do I download a URL in Fiddlerscript

3 Answers 543 Views
Extensions and Customization
This is a migrated thread and some comments may be shown as answers.
Varun
Top achievements
Rank 1
Iron
Varun asked on 09 Jun 2020, 06:32 AM

In "OnBeforeRequest()" event, I want to download a URL and then return it as "oSession.LoadResponseFromStream()".

 

I want to redirect to or something like that. What is the Fiddlerscript function to download URL in code and return it as body"?

3 Answers, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 09 Jun 2020, 03:37 PM

Hello Varun Agrawal,

 

Thank you for using Fiddler and FiddlerScript!

I am not entirely sure what you are trying to achieve but you could take a look at this documentation article where a number of examples are shown on how to use onBeforeRequest and onBeforeResponse events. Note the following (as stated in the article):

It is not possible to access the response objects inside OnBeforeRequest as they have not yet been created.
It is possible to use objects from the request inside OnBeforeResponse; however, any changes you make to those objects will not be seen by the server, as it has already received the request.
The above said you could find an example for changing the hostname and redirecting to a specific server:

// Point all requests for one port to a different port on a different server

    if (oSession.host=="www.bayden.com:8080") {
      oSession.host="test.bayden.com:9090";
    }

 

 

Regards,
Nick Iliev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Varun
Top achievements
Rank 1
Iron
answered on 09 Jun 2020, 03:45 PM

Hello Nick,

 

I will try to explain with a pseudo-code.

 

static function OnBeforeRequest2(oSession: Session) {

 String body = HttpClient.downloadUrl("http://localhost/something.php");

 oSession.LoadResponseFromTest(body);

}

 

I hope it make sense. First statement tries to use HTTP library to download an additional URL. Second statement return the downloaded body as response.

 

I don't want to make a redirect. I want to modify the content transparently so client doesn't see the redirect.

0
Nick Iliev
Telerik team
answered on 11 Jun 2020, 06:04 AM

Hello Varun Agrawal,

 

There are several things you could try. The first thing would be to check the solutions provided as examples in this documentation article where you could find an example of how to use utilSetResopnseBody and pathAndQuery.

If using HTTPS, then you could try to redirect like this

// Redirect traffic, including HTTPS tunnels 
if (oSession.HTTPMethodIs("CONNECT") && (oSession.PathAndQuery == "www.example.com:443")) { 
    oSession.PathAndQuery = "beta.example.com:443"; 
} 
if (oSession.HostnameIs("www.example.com")) oSession.hostname = "beta.example.com";

 

The above will change the hostname (from www.example.com to beta.example.com) but only in your session list. For the browser, the change will remain hidden.

Another approach is to call the utilCreateResponseAndBypassServer method and to set the headers and the body of the response (similar to what the AutoResponder Is doing). See this gist for a basic example.

 

Regards,
Nick Iliev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Extensions and Customization
Asked by
Varun
Top achievements
Rank 1
Iron
Answers by
Nick Iliev
Telerik team
Varun
Top achievements
Rank 1
Iron
Share this question
or