hot to get html from url requiring login

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 9
Reputation: Krimi is an unknown quantity at this point 
Solved Threads: 0
Krimi Krimi is offline Offline
Newbie Poster

hot to get html from url requiring login

 
0
  #1
Mar 17th, 2008
hi
i need to read html from a url requiring that i log in to the site.
how is that done? i think it depends on how the site is build?
its for a torrent site, and they often use the same template as far as i know.
the site im trying to read through c# is http://nordic-t.org/browse.php

this code works fine for getting any page, that doesnt require login:
  1. // Address of URL
  2. string URL = textBox1.Text;
  3. try
  4. {
  5. // Get HTML data
  6. WebClient client = new WebClient();
  7. Stream data = client.OpenRead(URL);
  8. StreamReader reader = new StreamReader(data);
  9. string str = "";
  10. str = reader.ReadLine();
  11.  
  12. while (str != null)
  13. {
  14. richTextBox1.AppendText(str);
  15. str = reader.ReadLine();
  16. }
  17. data.Close();
  18. }
  19. catch (WebException exp)
  20. {
  21. MessageBox.Show(exp.Message, "Exception");
  22. }

how do i merge username and password into all this?
i searched, but didnt find anything for doing it with a page using php. maybe i searched for the wrong things.. still kinda newbie with programming
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,602
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: hot to get html from url requiring login

 
0
  #2
Mar 18th, 2008
Without even bothering to question you about your motives, I shall get right to it:

The measures you will need to take may vary from site to site, and I for one do not know which methods this site uses to verify users. But it is important to note that it is quite possible that you can't access the "normal" page without logging in, or at least convincing the server that you have. This is because the server probably doesn't bother to send you the normal page (and it shouldn't) until you are verified as a user.

I would suggest that before running the script on that page, you use the web client to log in to the site. This will set any variables that the server may use to log/verify your authentication.

Next, if that web client you are using supports cookies, I would suggest turning them on. If it doesn't, get one that does. Whenever the server asks to write to a cookie, let it. Whenever it asks for the data in a cookie it wrote to, let it (don't let it read cookies it didn't write unless your web client is encapsulated, essentially meaning separated from IE, Firefox or whatever browsers you use). The reasons cookies are important, is that many sites use them to help handle user log ins (including the ones I get to work on)

Good luck.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 9
Reputation: Krimi is an unknown quantity at this point 
Solved Threads: 0
Krimi Krimi is offline Offline
Newbie Poster

Re: hot to get html from url requiring login

 
0
  #3
Mar 18th, 2008
ok, thanks. it doesn't seem to be as simple as i hoped i would be, but i will try.

and i can assure you, that my motives is 100% legal.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC