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
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.
// 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
Our thoughts here at Progress are with those affected by the outbreak.

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.
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
Our thoughts here at Progress are with those affected by the outbreak.