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

how to redirect a response to a random link?

1 Answer 449 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
nasekt
Top achievements
Rank 1
nasekt asked on 15 Oct 2014, 12:10 PM
if (oSession.oResponse.headers.ExistsAndContains("Content-Type","html")){
oSession.utilDecodeResponse();
var oBodyString = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
oSession["ui-color"]="yellow";
  var regex = /targetstring/gi ;
if (!oSession.uriContains("google")){
if (regex.test(oBodyString)) {

var request_arr = new Array("www.example.com", "www.bing.com", "www.google.com", "www.ads.com/", "www.time.com", "www.sandbox.com");
var wrl = request_arr[Math.floor(MathObject.random() * request_arr.length)];
oSession["ui-color"]="lavender";
oSession.fullUrl = "https://" + wrl ;

The script says, if the targetstring is present in the response body, then redirect to a random link/URL.

Am I doing it right? Could you  please quide me here?

Thank you.

1 Answer, 1 is accepted

Sort by
1
Eric Lawrence
Telerik team
answered on 16 Oct 2014, 04:38 PM
1. Please stop trying to interpret the response bytes like that. Use oSession.GetResponseBodyAsString() which is both simpler and works properly for non-UTF8 content.

2. Changing the request's URL after it has already returned a response won't do anything. You probably want to instead change oSession.responseCode to 307 and add a new response header oSession.oResponse["Location"] = "https://" + wrl;

That way, the client performs the redirect.

Regards,
Eric Lawrence
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

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