Could you post some code? I tested the scenario you described and the
'WebClient' object's 'UploadData' method returns the data of the file which
the server redirected the request to.
Okay at the bottom is the first Webpage that is returned and is the login page for the web page.
This is the data returned by the first read.
The code I use to try and read this that I think should work is
Private Function GetHTML(ByVal URL As String, Optional ByVal TimeOut As Integer = 10) As String
Dim cookieJar As CookieContainer = New CookieContainer
Dim payload As String
Dim webReq As HttpWebRequest
Dim webReps As WebResponse
Dim sr As StreamReader
Dim sw As StreamWriter
Dim txt As String
Try
' Set up our web request
webReq = CType(WebRequest.Create(New Uri(URL)), HttpWebRequest)
webReq.CookieContainer = cookieJar
webReq.Credentials = CredentialCache.DefaultCredentials
webReq.UserAgent = "BGClient"
webReq.KeepAlive = True
webReq.Headers.Set("Pragma", "no-cache")
webReq.Timeout = TimeOut * 1000
webReq.Method = "GET"
webReps = webReq.GetResponse
sr = New StreamReader(webReps.GetResponseStream)
txt = sr.ReadToEnd
sr.Close()
webReps.Close()
webReq = CType(WebRequest.Create(New Uri(URL)), HttpWebRequest)
webReq.CookieContainer = cookieJar
webReq.Credentials = CredentialCache.DefaultCredentials
webReq.UserAgent = "BGClient"
webReq.KeepAlive = True
webReq.Headers.Set("Pragma", "no-cache")
webReq.Timeout = TimeOut * 1000
webReq.Method = "POST"
webReq.ContentType = "application/x-www-form-urlencoded"
payload = "
[email protected]&pass=passw&c&usagelogin=Submit"
webReq.ContentLength = payload.Length
sw = New StreamWriter(webReq.GetRequestStream)
sw.write(payload)
sw.close()
webReps = webReq.GetResponse
sr = New StreamReader(webReps.GetResponseStream)
txt = sr.ReadToEnd.Trim
Debug.WriteLine(txt)
sr.Close()
webReps.Close()
GetHTML = txt
Catch
Return String.Empty
End Try
End Function
fquid is the username below and pass is the password. These are what I have seen passed thru IE
using IEHeaders to check. As I said I can read the first part but the second part of the sending the
username/password and getting the proper redirected page back fails.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<HEAD>
<TITLE>Login to TelstraClear HighSpeed Internet Usage
Meter</TITLE>
<META NAME="Keywords" CONTENT="login, authentication">
<META NAME="Description" CONTENT="Form to login to
TelstraClear HighSpeed Internet usage meter.">
<script>
function checkForm(theForm){
var err = "";
var u = trimString(theForm.fquid.value);
var p = trimString(theForm.pass.value);
if (u.length == 0){
err = err + "- Username cannot be empty!";
}
if (p.length == 0){
err = err + "\n- Password cannot be empty!";
}
if (err.length != 0)
{
alert(err);
return false;
}
else
{
return true;
}
}
function trimString(theString) {
while (theString.charAt(0) == " ") {
theString =
theString.substring(1,theString.length);
}
while (theString.charAt(theString.length - 1) == " ")
{
theString =
theString.substring(0,theString.length - 1);
}
return theString;
}
</script>
</head>
<body bgcolor="ffffff"
onLoad="document.forms.loginForm.fquid.focus();">
<form name="loginForm" method="POST" action="/usagemeter/index.cfm"
onSubmit="return checkForm(this)">
<img src="images/dot-clear.gif" width=1 height=1 vspace=2> <br>
<table align="center" cellpadding=2 cellspacing=0 border=0
bgcolor="#999999">
<tr>
<td>
<table cellpadding=5 cellspacing=0 border=0 bgcolor="#f0f0f0">
<tr><td><font face="Arial, Helvetica" size=2
color="#666666"><b>Welcome to TelstraClear HighSpeed Internet Usage
Meter. Please Login.</b></font> </td></tr>
<tr>
<td align="center">
<font face="Arial, Helvetica" size=2
color="#666666"><b>User
Name</b><br>(
[email protected])</font><br>
<input type="text" name="fquid" maxlength="50"
size="30" value=""><br>
<img src="images/dot-clear.gif" width=1
height=1 vspace=2><br>
<font face="Arial, Helvetica" size=2
color="#666666"><b>Password</b></font><br>
<input type="password" name="pass"
maxlength="30" size="30" value=""><br>
<img src="images/dot-clear.gif" width=1
height=1 vspace=2><br>
<INPUT type="Hidden" name="s" value="c">
<input type="submit" name="usagelogin"
value="Submit">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>