Login to secure webpage using system.net.webclient

B

Ben

Hi

I have the code below that I am using to login to my remote webpage.

The problem is that it seems to not post the data. I have heard that
ViewState can be a problem and that it may be necessary to retrieve the
ViewState field and Post it with the data, i have attempted test this by
copying the viewstate text out of the source and into the start of the
variable strPostData - as you can see commented out.

I am unsure why I do not get forwarded from the adminlogin.aspx page after
posting the data, could this be the viewstate or another issue?

Any advice would be much appreciated.

Thanks
B


Dim strURL As String
Dim strPostData As String

Dim byteResponse() As Byte

Dim i As Integer

Dim strViewState As String

strURL = strHttpLocation & "adminlogin.aspx"

strPostData =
"UsernameTextBox=username&PasswordTextBox=1234&LoginButton=Login"

'strPostData =
"__VIEWSTATE=dDwtNDU0NDA4NTk3Ozs+hQAoe3316Ljm9GtmhxCl3GsRZjw=&UsernameTextBox=username&PasswordTextBox=1234&LoginButton=Login"

'login

gobjWebClient.Headers.Add("Content-Type",
"application/x-www-form-urlencoded")

byteResponse = gobjWebClient.UploadData(strURL, "POST",
System.Text.Encoding.ASCII.GetBytes(strPostData))

TextBox1.Text = System.Text.Encoding.ASCII.GetString(byteResponse)
 
K

Ken Tucker [MVP]

Hi,

http://msdn.microsoft.com/library/d...fsystemnetwebrequestclasscredentialstopic.asp

Ken
-------------------------
Hi

I have the code below that I am using to login to my remote webpage.

The problem is that it seems to not post the data. I have heard that
ViewState can be a problem and that it may be necessary to retrieve the
ViewState field and Post it with the data, i have attempted test this by
copying the viewstate text out of the source and into the start of the
variable strPostData - as you can see commented out.

I am unsure why I do not get forwarded from the adminlogin.aspx page after
posting the data, could this be the viewstate or another issue?

Any advice would be much appreciated.

Thanks
B


Dim strURL As String
Dim strPostData As String

Dim byteResponse() As Byte

Dim i As Integer

Dim strViewState As String

strURL = strHttpLocation & "adminlogin.aspx"

strPostData =
"UsernameTextBox=username&PasswordTextBox=1234&LoginButton=Login"

'strPostData =
"__VIEWSTATE=dDwtNDU0NDA4NTk3Ozs+hQAoe3316Ljm9GtmhxCl3GsRZjw=&UsernameTextBox=username&PasswordTextBox=1234&LoginButton=Login"

'login

gobjWebClient.Headers.Add("Content-Type",
"application/x-www-form-urlencoded")

byteResponse = gobjWebClient.UploadData(strURL, "POST",
System.Text.Encoding.ASCII.GetBytes(strPostData))

TextBox1.Text = System.Text.Encoding.ASCII.GetString(byteResponse)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top