Problem accessing link by using HttpWebRequest or WebBrowser

Posted by Adicrz2004 under C# on 4/22/2012 | Points: 10 | Views : 1407 | Status : [Member] | Replies : 1
Hello,

I have problem accessing links from a website. The site is http://www.tv-links.eu/tv-shows/A.html and a link that I need to access looks like this in html code : <a href="/tv-shows/Absolute-Power_25833/" class="list cfix"> <span class="c1">Absolute Power</span> <span class="c2">2003</span> </a> .

I try to access this link by forming the complete address : http://www.tv-links.eu/tv-shows/Absolute-Power_25833/, but when using either the HttpWebRequest class or the WebBrowser class, the page that is opened is the main page of the site, and not the one I give as a link.

Here is the code I use for HttpWebRequest :
//request to access the link
HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(link));

//the response
HttpWebResponse webRes = (HttpWebResponse)webReq.GetResponse();

//gets the stream of data from the response
Stream streamResponse = webRes.GetResponseStream();
StreamReader sr = new StreamReader(streamResponse);

content = sr.ReadToEnd();
sr.Close();
streamResponse.Close();

And for the webBrowser:
this.webBrowserForNavigation.Navigate(link);

Can someone offer instructions on how to access the intended link ?

Thank you.

adi


Responses

Posted by: Ajayk3 on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
I had tried on my machine but it is giving me correct result.

The code i m using

string link = "http://www.tv-links.eu/tv-shows/Absolute-Power_25833/";

HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(link));

//the response
HttpWebResponse webRes = (HttpWebResponse)webReq.GetResponse();

//gets the stream of data from the response
Stream streamResponse = webRes.GetResponseStream();
StreamReader sr = new StreamReader(streamResponse);

string content = sr.ReadToEnd();
sr.Close();
streamResponse.Close();

Are you doing any other mistake? Like Not using IsPostBack property on page load .



Adicrz2004, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response