L
Lorenzo
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?aktion=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?aktion=login&username=xxxx&password=xxxx&dest=/admin/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(object sender, System.EventArgs e)
{
string postdata;
WebClient page = new WebClient();
CredentialCache cache = new CredentialCache();
CookieContainer ccContainer = new CookieContainer();
ASCIIEncoding encoding = new ASCIIEncoding();
HttpWebRequest request
=(HttpWebRequest)WebRequest.Create("https://xxxx.xxxx.com/admin/login.asp");
request.AllowAutoRedirect = false;
request.Method = "POST";
request.ContentType = @"application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/4.0 (compatible;" +
" MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";
request.CookieContainer = new CookieContainer();
postdata = "?aktion=login&username="+
HttpUtility.UrlDecode("massimiliano.del.vita") + "&password=" +
HttpUtility.UrlDecode("miami") +
"&dest=" + HttpUtility.UrlDecode("/admin/Default.asp");
request.Credentials = new NetworkCredential("xxxx","xxxx");
request.CookieContainer.Add(ccContainer.GetCookies(new
Uri("https://xxxx.xxxxx.com/admin/login.asp"));
byte[] buf = encoding.GetBytes(postdata);
request.ContentLength = buf.Length;
Stream str = request.GetRequestStream();
str.Write(buf,0,buf.Length);
str.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if(request.HaveResponse)
{
Stream str2 = response.GetResponseStream();
StreamReader strReader = new StreamReader(str2);
txtHtml.Text = strReader.ReadToEnd().Trim();
string result = strReader.ReadToEnd();
}
}
could u help me? tnx
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?aktion=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?aktion=login&username=xxxx&password=xxxx&dest=/admin/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(object sender, System.EventArgs e)
{
string postdata;
WebClient page = new WebClient();
CredentialCache cache = new CredentialCache();
CookieContainer ccContainer = new CookieContainer();
ASCIIEncoding encoding = new ASCIIEncoding();
HttpWebRequest request
=(HttpWebRequest)WebRequest.Create("https://xxxx.xxxx.com/admin/login.asp");
request.AllowAutoRedirect = false;
request.Method = "POST";
request.ContentType = @"application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/4.0 (compatible;" +
" MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";
request.CookieContainer = new CookieContainer();
postdata = "?aktion=login&username="+
HttpUtility.UrlDecode("massimiliano.del.vita") + "&password=" +
HttpUtility.UrlDecode("miami") +
"&dest=" + HttpUtility.UrlDecode("/admin/Default.asp");
request.Credentials = new NetworkCredential("xxxx","xxxx");
request.CookieContainer.Add(ccContainer.GetCookies(new
Uri("https://xxxx.xxxxx.com/admin/login.asp"));
byte[] buf = encoding.GetBytes(postdata);
request.ContentLength = buf.Length;
Stream str = request.GetRequestStream();
str.Write(buf,0,buf.Length);
str.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if(request.HaveResponse)
{
Stream str2 = response.GetResponseStream();
StreamReader strReader = new StreamReader(str2);
txtHtml.Text = strReader.ReadToEnd().Trim();
string result = strReader.ReadToEnd();
}
}
could u help me? tnx