Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the Redirected URL from the Original URL
    primarykey
    data
    text
    <p>I have a table in my database which contains the URLs of some websites. I have to open those URLs and verify some links on those pages. The problem is that some URLs get redirected to other URLs. My logic is failing for such URLs.</p> <p>Is there some way through which I can pass my original URL string and get the redirected URL back?</p> <p>Example: I am trying with this URL: <a href="http://individual.troweprice.com/public/Retail/xStaticFiles/FormsAndLiterature/CollegeSavings/trp529Disclosure.pdf" rel="noreferrer">http://individual.troweprice.com/public/Retail/xStaticFiles/FormsAndLiterature/CollegeSavings/trp529Disclosure.pdf</a></p> <p>It gets redirected to this one: <a href="http://individual.troweprice.com/staticFiles/Retail/Shared/PDFs/trp529Disclosure.pdf" rel="noreferrer">http://individual.troweprice.com/staticFiles/Retail/Shared/PDFs/trp529Disclosure.pdf</a></p> <p>I tried to use following code:</p> <pre><code>HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Uris); req.Proxy = proxy; req.Method = "HEAD"; req.AllowAutoRedirect = false; HttpWebResponse myResp = (HttpWebResponse)req.GetResponse(); if (myResp.StatusCode == HttpStatusCode.Redirect) { MessageBox.Show("redirected to:" + myResp.GetResponseHeader("Location")); } </code></pre> <p>When I execute the code above it gives me <code>HttpStatusCodeOk</code>. I am surprised why it is not considering it a redirection. If I open the link in Internet Explorer then it will redirect to another URL and open the PDF file.</p> <p>Can someone help me understand why it is not working properly for the example URL?</p> <p>By the way, I checked with Hotmail's URL (<a href="http://www.hotmail.com" rel="noreferrer">http://www.hotmail.com</a>) and it correctly returns the redirected URL.</p> <p>Thanks,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload