Results 1 to 6 of 6

Thread: Accessing a website with a username and password

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Location
    Tehran, Iran
    Posts
    8

    Accessing a website with a username and password

    I want to read some data from a website using a user and pass. Actually the website is accessible without user and pass but I want some data which is only accessible with my user & pass (consider yahoo.com which is accessible even if you're not signed in). I don't know whether vb can do this or not.
    I would be so grateful for any help.
    Last edited by diba; Sep 30th, 2010 at 04:09 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Accessing a website with a username and password

    You can use a WebClient to get data from a web site and it lets you specify user credentials. There are lots of examples around so you should search, but even before that you should read the MSDN documentation for the WebClient class and its members.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Location
    Tehran, Iran
    Posts
    8

    Re: Accessing a website with a username and password

    I read the MSDN documentation and I used this code:
    Code:
    request.Credentials = New System.Net.NetworkCredential("user", "pass", "domain")
    But nothing changed. Actually there are some ambiguities in the above command for me. I don't know when and how it uses the username and password. I mean in the destination url the "log in" link is in a corner of the page and for signing in I should go there and enter my username and password. Now how this command find the right place to enter user and pass?

    Here is the whole story:
    I want to search some terms in a site (IMDB) automatically and I want the site to redirect the search page to the best match for the entered query. This redirection can be possible when I'm logged in because I set this option in my account's search preferences.

    Now I want the site to search the terms through my user and pass but it still searches without logging in. I entered the "search page" and the "log in page" as "domain" in that command but nothing changed.
    I would be grateful for any help.
    Last edited by diba; Oct 3rd, 2010 at 03:06 PM.

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Accessing a website with a username and password

    Hey,

    Personally, I would be more inclined to use the HttpWebRequest class for this, but perhaps that is just my personal opinion.

    Here is what I would do...

    1) Create a CookieContainer, this will be used to capture the cookies when you log into the site
    2) Make an initial HttpWebRequest to the login pass, providing your username and password in the request, and pass the CookieContainer into the request
    3) If you login is successful, your CookieContainer will now be filled with the cookie that you can use on subsequent requests to the site
    4) Make additional requests to the site, still using the same CookieContainer, and you should be able to access all pages, as you would if you were logged into the site

    Here is some more information:

    http://msdn.microsoft.com/en-us/libr...container.aspx

    Hope that helps!

    Gary

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Location
    Tehran, Iran
    Posts
    8

    Re: Accessing a website with a username and password

    I think it is not possible to log in websites such as Yahoo with request.credentials, and to use CookieContainer I think I should log in at least one time that the cookie can be stored.

    I logged in with IE and visual studio's browser and it made the cookie, because after that login, the website logs me in automatically. But when I go to the page within my program it doesn't seem to be logged in, I mean probably when I request the address through my program it doesn't use the cookie which is stored by IE or visual studio's browser.

    So now I want to log in the site through my program. To do this I should write my username and password in two text boxes in the log in page, But I don't know how to do this. I've searched a lot about posting data in a webpage but I couldn't find anything. I want some help please!

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Accessing a website with a username and password

    Quote Originally Posted by diba View Post
    I think it is not possible to log in websites such as Yahoo with request.credentials, and to use CookieContainer I think I should log in at least one time that the cookie can be stored.
    Why wouldn't you be able to?

    Have you tried it? As long as you hit the login pass, validate successfully, and grab the cookie, then pass this cookie in with any additional requests that you make, then you should be fine.

    Have you tried it?

    Gary

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width