获得从HTML页面登录背后 [英] Getting HTML from a page behind a login

查看:135
本文介绍了获得从HTML页面登录背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是一个跟进到我的 previous问题有关从ASPX页面获取HTML。我决定用WebClient的对象来尝试,但问题是,我得到的登录页面的HTML,因为需要登录。我试图在登录使用WebClient的对象:

This question is a follow up to my previous question about getting the HTML from an ASPX page. I decided to try using the webclient object, but the problem is that I get the login page's HTML because login is required. I tried "logging in" using the webclient object:

WebClient ww = new WebClient();

 ww.DownloadString("Login.aspx?UserName=&Password=");

 string html = ww.DownloadString("Internal.aspx");

但我仍然获得登录页面的所有时间。我知道的用户名信息不是存储在cookie中。我必须做一些错误或遗漏的重要组成部分。有谁知道这可能是什么?

But I still get the login page all the time. I know that the username info is not stored in a cookie. I must be doing something wrong or leaving out an important part. Does anyone know what it could be?

推荐答案

只是通过有效的登录参数给定的URI。如果您排忧解难。

Just pass valid login parameters to a given URI. Should help you out.

如果您没有登录,你不应该试图绕过它的信息。

public static string HttpPost( string URI, string Parameters )
      {
         System.Net.WebRequest req = System.Net.WebRequest.Create( URI );
         req.ContentType = "application/x-www-form-urlencoded";
         req.Method = "POST";
         byte[] bytes = System.Text.Encoding.ASCII.GetBytes( Parameters );
         req.ContentLength = bytes.Length;
         System.IO.Stream os = req.GetRequestStream();
         os.Write( bytes, 0, bytes.Length );
         os.Close();
         System.Net.WebResponse resp = req.GetResponse();
         if ( resp == null ) return null;
         System.IO.StreamReader sr = new System.IO.StreamReader( resp.GetResponseStream() );
         return sr.ReadToEnd().Trim();
      }

这篇关于获得从HTML页面登录背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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