Hi i'm writing some code that retrieve the html source code of an asp page.
The problem is that if i go directly to this page the browser redirect me to
a login page where are two textbox in a html form.
<form action="/admin/login.asp?aktio n=login" method="POST" name="login">
<table border="2" align="center">
<tr>
<td>
<b>Username:</b>
</td>
<td>
<input class="basic" type="text" size="15" name="username" >
</td>
</tr>
<tr>
<td>
<b>Password:</b>
</td>
<td>
<input class="basic" type="password" size="15" name="password" >
</td>
<td>
<input class="basic" type="submit" name="enterbut" value="Enter">
<input type="hidden" name="dest" value="">
<input type="hidden" name="qs" value="">
</td>
if i write in the address bar the link
https://xxx.xxx.com/admin/login.asp?...in/Default.asp
i go in the default.asp page.
now...i write this code in c# but it doesn't work...in the txtHtml textbox
is shown always the html source of the login.asp page...
private void Button1_Click(o bject sender, System.EventArg s e)
{
string postdata;
WebClient page = new WebClient();
CredentialCache cache = new CredentialCache ();
CookieContainer ccContainer = new CookieContainer ();
ASCIIEncoding encoding = new ASCIIEncoding() ;
HttpWebRequest request
=(HttpWebReques t)WebRequest.Cr eate("https://xxxx.xxxx.com/admin/login.asp");
request.AllowAu toRedirect = false;
request.Method = "POST";
request.Content Type = @"applicatio n/x-www-form-urlencoded";
request.UserAge nt = "Mozilla/4.0 (compatible;" +
" MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";
request.CookieC ontainer = new CookieContainer ();
postdata = "?aktion=login& username="+
HttpUtility.Url Decode("massimi liano.del.vita" ) + "&password= " +
HttpUtility.Url Decode("miami") +
"&dest=" + HttpUtility.Url Decode("/admin/Default.asp");
request.Credent ials = new NetworkCredenti al("xxxx","xxxx ");
request.CookieC ontainer.Add(cc Container.GetCo okies(new
Uri("https://xxxx.xxxxx.com/admin/login.asp"));
byte[] buf = encoding.GetByt es(postdata);
request.Content Length = buf.Length;
Stream str = request.GetRequ estStream();
str.Write(buf,0 ,buf.Length);
str.Close();
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();
if(request.Have Response)
{
Stream str2 = response.GetRes ponseStream();
StreamReader strReader = new StreamReader(st r2);
txtHtml.Text = strReader.ReadT oEnd().Trim();
string result = strReader.ReadT oEnd();
}
}
could u help me? tnx