C# HAP how to get redirected url

c# html-agility-pack

Question

This is an ebay page

http://www.ebay.com/itm/GRUEN-RUNNING-PRECISION-WRIST-WATCH-/230718830945?pt=Pocket_Watches&hash=item35b7e9f961

I am using C# agility pack to get the 'print' version page from this link . 'Print' link is at the middle right side of this page . Agilitypack is returning this link :

http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&rt=nc&item=230718830945&si=a8iGAIchyvEbn7KveYFZ5QbEE7o%3D&print=all&category=3940

When I am loading this link its returning another page , not the actual one . Though clicking on 'print' works well . As far as i understand 'print' link is being redirected to another page. I have checked some solution of stackoverflow . not worked for this case . There is a .dll file in the link/path . Any suggestion to solve this problem ??

thanks in advance

Popular Answer

The link points to http://cgi.ebay.com/ which redirects to http://www.ebay.com/itm/ the rest of the URL is identical, so you can just use string.Replace("http://cgi.ebay.com/", "http://www.ebay.com/itm/")

Or if you want to do it cleanly, use this code:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(print_url);
HttpWebResponse myResp = (HttpWebResponse)req.GetResponse();

string new_print_url = myResp.ResponseUri;



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why