如何登录asp.net中的任何网站 [英] how to login to any website in asp.net

查看:82
本文介绍了如何登录asp.net中的任何网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i希望从我的应用程序中收集来自我的应用程序的数据,用户将输入凭据并在提交时我的应用程序将使用该用户凭据登录到某个网站并获取数据



如何通过登录访问登录的受保护页面。我想在我的应用程序中简单地放两个文本框用户名和密码,例如,它需要连接到这个站点(论坛)或hotmail.com,记录成员哪些用户名和密码是由那些文本框提供的,而不是获取数据...



请提供教程,链接或示例



谢谢

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

推荐答案

这称为网络抓取

http://en.wikipedia.org/wiki/Web_scraping [ ^ ]。



您可以使用类 System.Net.HttpWebRequest 来完成:

http://msdn.microsoft.com/en- us / library / system.net.httpwebrequest.aspx [ ^ ]。



如需了解更多详情,请参阅我过去的答案:

从网页获取特定数据 [ ^ ],

如何从其他网站获取数据 [ ^ ]。



你不应该填写任何文本框(这看起来毫无意义)。您需要在输入表单中将相同的数据放在HTTP请求中。控件的值通过HTML属性name的值进入HTTP请求。如果这一开始很难实现,那么您可以开发一个简单的表单和一个简单的ASP.NET页面来获取发布数据,以了解它在HTTP中的外观。根据这种经验,您将能够首先模拟测试页面的请求,然后再模拟您的真实网站。



-SA
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


代码示例

Code example
private static WebClient CreateWebClient(string userId, string password)
{
    if (string.IsNullOrEmpty(userId))
        return new WebClient();
    else
        return new WebClient
        {
            Credentials = new NetworkCredential(userId, password)
        };
}




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;

    }
}





您只需使用或修改此代码并添加代码库您可以将其用作应用程序中的通用用法。代码是自我解释的,所以你很容易得到一切。



我可以访问这个


这篇关于如何登录asp.net中的任何网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆