0

I have a URL

ex. www.siteA.com/?UGLY_KEY_12312432342SSDFSD

It then redirects you to:

www.siteB.com/?ANOTHER_UGLY_KEY_ASDASDFS2342342

What i need is some way to catch the redirect URL of siteB

I've tried JQuery $.ajax

and I am swamped with

No 'Access-Control-Allow-Origin' header is present on the requested resource.

I am aware that CORS is the typical way to go, but it is impossible in my case.

Shouldn't this be easier security wise as it is a mere, GET?

$.ajax({
            type: "GET",
            url: "www.siteA.com/?UGLY_KEY_12312432342SSDFSD",

            dataType: "json",
            success: function (response, status, request) {

                    // data.redirect contains the string URL to redirect to
                alert(response.redirectUrl);


            }    

        }
Pinch
  • 4,009
  • 8
  • 40
  • 60

1 Answers1

0

I need to use a HttpWebRequest on the server side because of CORS Permission issues.

Here it is:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://www...");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "GET";
httpWebRequest.AllowAutoRedirect = false;
httpWebRequest.Timeout = 10000;
httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36";

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

string THEREDIRECTURL = httpResponse.GetResponseHeader("Location");
Pinch
  • 4,009
  • 8
  • 40
  • 60