0

基本上我只为我的大学生制作一个聊天应用程序,为此我必须通过检查 UMS(大学管理系统)的详细信息来确保他们是真实的,并获取他们的基本详细信息,以便他们真正聊天。我几乎完成了我的聊天应用程序,只剩下登录名。

所以我想通过我的网站从通用处理程序登录到我的 UMS 页面。然后导航到其中的另一个页面以访问保持会话活动的基本信息。

我对 httpwebrequest 进行了研究,但未能使用我的凭据登录。

https://ums.lpu.in/lpuums (在 asp.net 中制作)

我确实尝试过其他帖子中的登录代码。

我是这部分的新手,所以请耐心等待.. 任何帮助将不胜感激。

4

2 回答 2

0

如果没有通过定义的 API 与 UMS 进行实际握手,您最终会抓取 UMS html,由于各种原因,这很糟糕。

我建议您阅读Single Sign On (SSO)

关于 SSO 和 ASP.NET 的几篇文章 - 1. Codeproject 2. MSDN 3. asp.net forum

编辑 1

虽然,我认为这是一个坏主意,因为你说你没有选择,这里有一个链接显示Html Agility Pack如何帮助抓取网页。

当心屏幕抓取的缺点,UMS 的更改不会传达给您,您会发现您的应用程序突然无法运行。

于 2013-03-09T12:16:02.933 回答
0
public string Scrap(string Username, string Password)
    {
        string Url1 = "https://www.example.com";//first url
        string Url2 = "https://www.example.com/login.aspx";//secret url to post request to

        //first request
        CookieContainer jar = new CookieContainer();
        HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(Url1);
        request1.CookieContainer = jar;
        //Get the response from the server and save the cookies from the first request..
        HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();

        //second request
        string postData = "***viewstate here***";//VIEWSTATE
        HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(Url2);
        request2.CookieContainer = jar;
        request2.KeepAlive = true;
        request2.Referer = Url2;
        request2.Method = WebRequestMethods.Http.Post;
        request2.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request2.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
        request2.ContentType = "application/x-www-form-urlencoded";
        request2.AllowWriteStreamBuffering = true;
        request2.ProtocolVersion = HttpVersion.Version11;
        request2.AllowAutoRedirect = true;

        byte[] byteArray = Encoding.ASCII.GetBytes(postData);
        request2.ContentLength = byteArray.Length;

        Stream newStream = request2.GetRequestStream(); //open connection
        newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
        newStream.Close();

        HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
        using (StreamReader sr = new StreamReader(response2.GetResponseStream()))
        {
            responseData = sr.ReadToEnd();
        }

        return responseData;
    }

这是对我有用的代码,任何人都可以添加链接和视图状态以供 asp.net 网站报废,您也需要处理 cookie。对于其他网站(非 asp.net),它们不需要视图状态。使用 fiddler 查找添加标题和视图状态或 cookie 所需的内容。如果有人遇到问题,希望这会有所帮助。:)

于 2013-03-10T12:40:55.493 回答