Getting HTML from a page behind a login

前端 未结 8 1999
甜味超标
甜味超标 2021-01-16 05:59

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

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-16 06:28

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

    If you don't have login information you shouldn't be trying to circumvent it.

    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();
          }
    

提交回复
热议问题