Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi ,
i want to gather data from ANOTHER website from my application where user will enter credentials and on submit my application will login to some website using that user credentials and get data

how i can access the logged in protected pages by logging in . i want to simply put two textbox username and password , in my application , for example and it need to be connect to this site (forum) or hotmail.com, logging the member which username and password was provided by those textbox and than get data...

Please provide me tutorials , links or examples

thanks
Posted
Updated 18-Feb-13 12:28pm
v2
Comments
Sergey Alexandrovich Kryukov 18-Feb-13 18:25pm    
Do you want to develop a login page and the code, or you want to login on existing site?
—SA
Shan Ali Khan 18-Feb-13 18:27pm    
i want to gather data from ANOTHER website from my application where user will enter credentials and on submit my application will login to some website using that user credentials and get data.. how i can do so ?

This is called Web scraping:
http://en.wikipedia.org/wiki/Web_scraping[^].

You can do it using the class System.Net.HttpWebRequest:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].

For further detail, please see my past answers:
get specific data from web page[^],
How to get the data from another site[^].

You should not fill in any text boxes (and this seems totally pointless). You need to put the same data in HTTP request as the input form does. The values of the controls come into HTTP request by the values of the HTML attribute "name". If this is difficult to achieve at first, you can develop a simple form and a simple ASP.NET page getting post data, to see how it should look in HTTP. Based if this experience, you will be able to mimic the request for your test page first, and later to your "real" site.

—SA
 
Share this answer
 
Comments
_Amy 18-Feb-13 22:57pm    
Nicely explained. +5!
Sergey Alexandrovich Kryukov 18-Feb-13 23:07pm    
Thank you, Amy.
—SA
Code example
C#
private static WebClient CreateWebClient(string userId, string password)
{
    if (string.IsNullOrEmpty(userId))
        return new WebClient();
    else
        return new WebClient
        {
            Credentials = new NetworkCredential(userId, password)
        };
}

C#
public static string GetData(string userId, string password, string url)
{
    using (WebClient client = CreateWebClient(userId, password))
    {
        client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
        byte[] bytData = client.DownloadData(new Uri(url));
        string download = Encoding.ASCII.GetString(bytData);
        return download;

    }
}


You just use or modified this code and add your code base though you can use that as generalize use from your applications. Code is self explanatory so you easily get everything.

Indetail you can visit this
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900