how to redirect a response to a random link?

2 posts, 0 answers
  1. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 15 Oct 2014 Link to this post

    if (oSession.oResponse.headers.ExistsAndContains("Content-Type","html")){
    var oBodyString = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
      var regex = /targetstring/gi ;
    if (!oSession.uriContains("google")){
    if (regex.test(oBodyString)) {

    var request_arr = new Array("", "", "", "", "", "");
    var wrl = request_arr[Math.floor(MathObject.random() * request_arr.length)];
    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.
  2. Eric Lawrence
    Eric Lawrence avatar
    832 posts

    Posted 16 Oct 2014 Link to this post

    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.

    Eric Lawrence

    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.

Back to Top