Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem reading URL

Status
Not open for further replies.

maxdamme

Programmer
May 21, 2007
10
IL
I've got a strange problem. I'll try to explain:
There is a webpage (url1) where there is a linkbutton to another url(url2). If in internet explorer i navigate first to url1 and then to url2 there is no problem but if I open new explorer and want to go staight to url2 then i get some message from the site that data missing.
I guess there is some session variables that the site holds and when i try to come to url2 without visiting url1 first it doesn't work.

Now to the question, how can i read the data from url2 from C# code?
I tried making the two requests one after another but it didn't help:

req = (HttpWebRequest)WebRequest.Create(url1);
res = (HttpWebResponse)req.GetResponse();
req = (HttpWebRequest)WebRequest.Create(url2);
res = (HttpWebResponse)req.GetResponse();
sr = new StreamReader(res.GetResponseStream());
line = sr.ReadToEnd();

It is very important to me to make that work. I'll appriciate any help. If after my description something not clear feel free to ask.
Thanx in advance.
Max.
 
what exactly is the error message?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
To see when it doesn't work, you need to open new IE and copy paste URL2.
 
it seems the data is only accessible after visiting url1 within the same session. do you have access the the websites source code or developers. they may be able to point you in the right direction.

there may be a cookie that's set in response1 which needs to be copied (how, I don't know or if it's possible) to request 2 so you can retrieve the dat.




Jason Meckley
Programmer
Specialty Bakers, Inc.
 
So there is no way to enter this two links from the same session?
 
not to my knowledge, but I haven't worked with WebRequest. if there is a session variable or cookie required some form of information must be went with the response and placed on the client. when the client makes a 2nd request this information could be sent and the server know it's a different request from the same computer.

a quick google search lead me here [] this post onlines the bascis, moderate and advanced task of the WebRequest.Create().

what you want to do, should be possible, just not as simple as contacting a single URL.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top