简体   繁体   中英

how Login to a website using c# and read the contents of the logged in webpage (stream)?

I would like to know if its possible at all for a website developed using asp.net, and, if so, could someone please give me a few pointers on how to do it?

There are different ways you can do this.If you are doing it with ASP.NET I would suggest you web-services. People using API can pass username and encoded password over network.Share a secret key with the client for encoding passwords.

This might help http://blogs.sitepoint.com/single-sign-web-service-asp-net/ .

By passing a username and a hashed password of the user to method u can authenticate. The method queries the database to see if a row exists that contains both the username and the password. If a row is found, the user is authenticated, return true. Otherwise, we've been given incorrect credentials, and a false is returned.

If you need to return a stream you can build the stream by reading some file Using File.IO StreamReader and return it as a response.

If you want to take advantage of a third party website, you may want to use a WebClient class which will permit to fetch webpages and keep cookies in a CookieContainer class.

By making different web requests you will be able to POST (authentication) forms or even open HTTP stream for media elements such as videos. It's a bit hard to parse HTML but it's doable.

You just need to think as a web browser.

By the way, don't forget not to scrap elements under copyright.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM