473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

posting login credentials and __VIEWSTATE using HttpWebRequest fails

I have been raking my brains on why this does not work. I get back the same
login screen again instead of the home page redirection which should occur
after a successful login:

'create a cookie container so it can be shared between requests
so that authentication can be maintained
Dim objCookieCont As New CookieContainer

'create request to get the __VIEWSTATE of Authorize.NET's
Logon.aspx page
Dim objRequest As HttpWebRequest =
WebRequest.Create("https://account.authorize.net/ui/themes/anet/Logon.aspx")
objRequest.CookieContainer = objCookieCont

'get initial Logon page
Dim objReader As New
IO.StreamReader(objRequest.GetResponse().GetRespon seStream())
Dim strResponseString As String = objReader.ReadToEnd()
objReader.Close()

'parse page for VIEWSTATE value
Dim objRegEx As New Regex("__VIEWSTATE"" value="".*""")
Dim objMatch As Match = objRegEx.Match(strResponseString)
If Not objMatch.Success Then _
Throw New ApplicationException("Could not parse __VIEWSTATE
from Authorise.Net's Logon.aspx.")
Dim strViewState As String = objMatch.ToString
strViewState = strViewState.Replace("__VIEWSTATE"" value=", "")
strViewState = strViewState.Replace("""", "")

'create data posting
Dim objConfig As Specialized.NameValueCollection =
ConfigurationManager.GetSection("CreditCardTrans/Authorise.NET")
Dim strPostData As String =
String.Format("__VIEWSTATE={0}&MerchantLogin={1}&P assword={2}",
strViewState, objConfig("Login"), objConfig("Password"))
strPostData = HttpUtility.UrlEncode(strPostData)

'create new request for credential submittion
objRequest =
WebRequest.Create("https://account.authorize.net/ui/themes/anet/Logon.aspx")
With objRequest
.CookieContainer = objCookieCont
.Method = "POST"
.ContentType = "application/x-www-form-urlencoded"
.ContentLength = strPostData.Length
End With

'add data post to request
Dim objWriter As New
IO.StreamWriter(objRequest.GetRequestStream())
objWriter.Write(strPostData)
objWriter.Close()

'get response
objReader = New
IO.StreamReader(objRequest.GetResponse().GetRespon seStream())
strResponseString = objReader.ReadToEnd()
objReader.Close()
Response.Write(strResponseString)

What is strange is that the following html works (just to prove that this
site can be logged into) however I can not use it like this because I need
to do multiple followup calls after authentication which need to use the
same session cookie:

<form name="form1" method="post"
action="https://account.authorize.net/ui/themes/anet/Logon.aspx">
<input type="hidden" name="__VIEWSTATE"
value="dDw2ODc5MDg1MDk7dDw7bDxpPDA+O2k8MT47aTw3Pjs +O2w8dDxwPGw8VGV4dDs+O2w8QXV0aG9yaXplLk5FVCBXZWxjb 21lOz4+Ozs+O3Q8O2w8aTwwPjs+O2w8dDw7bDxpPDA+Oz47bDx 0PHA8cDxsPFZpc2libGU7PjtsPG88Zj47Pj47PjtsPGk8MT47a TwzPjtpPDU+O2k8Nj47PjtsPHQ8cDxsPGhyZWY7PjtsPC91aS9 0aGVtZXMvYW5ldC9sb2dvbi5hc3B4P3N1Yj1sb2dvdXQ7Pj47O z47dDxwPGw8aHJlZjs+O2w8amF2YXNjcmlwdDogdmFyIHdpbiA 9IHdpbmRvdy5vcGVuKCcvdWkvdGhlbWVzL2FuZXQvQ29udGFjd FVzL0ZlZWRiYWNrLmFzcHgnLCAnRmVlZGJhY2snLGNvbmZpZz0 naGVpZ2h0PTUwMCx3aWR0aD03NTAsc2Nyb2xsYmFycz0wLCByZ XNpemFibGU9MScpXDs7Pj47Oz47dDxwPGw8aHJlZjs+O2w8amF 2YXNjcmlwdDogdmFyIHdpbiA9IHdpbmRvdy5vcGVuKCcvdWkvd GhlbWVzL2FuZXQvQ29udGFjdFVzL1N1cHBvcnQuYXNweCcsJ3N 1cHBvcnQnLGNvbmZpZz0naGVpZ2h0PTUwMCx3aWR0aD03NTAsc 2Nyb2xsYmFycz0wLCByZXNpemFibGU9MScpOz4+Ozs+O3Q8O2w 8aTwxPjs+O2w8dDxwPGw8aHJlZjs+O2w8amF2YXNjcmlwdDp2Y XIgd2luID0gd2luZG93Lm9wZW4oJy91aS90aGVtZXMvYW5ldC9 Db250YWN0VXMvQ2hhdC5hc3B4JywnY2hhdCcsY29uZmlnPSdoZ WlnaHQ9MzUwLHdpZHRoPTUwMCxzY3JvbGxiYXJzPTAsIHJlc2l 6YWJsZT0xJylcOzs+Pjs7Pjs+Pjs+Pjs+Pjs+Pjt0PDtsPGk8M T47PjtsPHQ8cDxwPGw8VmlzaWJsZTs+O2w8bzxmPjs+Pjs+Ozs +Oz4+Oz4+Oz7rZCEFmJBwE1vGe4gpM1ANQ6UhNA=="
/>
<input type="hidden" name="MerchantLogin" value="username">
<input type="hidden" name="Password" value="password">
</form>
<script language="javascript">document.all.form1.submit(); </script>

Here I hardcoded the viewstate taken from login page just to test.

Thanks
Perry

May 10 '06 #1
0 4267

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ollie | last post by:
I have an aspx page that contains a web control that contains 2 text boxes and button to submit the text. I am trying to submit text and collect the response from a console application, but it is...
1
by: Tom Jones | last post by:
Hi, I am using the HttpWebRequest and HttpWebResponse classes to pull information from a web server on the internet. I have an account on one of the webservers that I need to log into...
9
by: buran | last post by:
Dear ASP.NET Programmers, How can I post data to an ASP.NET login page and pass authentication? The login page uses forms authentication, users must supply usernames and password and have to...
8
by: Pazza | last post by:
Hi, Is there a way to cause the form submit button click event handler to fire when posting to a aspx page using httpwebrequest. In my tests the load event fires but not by button click event....
7
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
0
by: barrybevel | last post by:
Hi, I'm trying to login to the www.vodafone.ie website using HttpWebRequest. It works fine with IE/Firefox and the .NET Web Control too, just not with my code. I think it's a redirect 302...
1
by: twebb72 | last post by:
Scratching my head for a while on this one... This project uses code from "Understanding HttpWebRequest CookieContainer?" post on this site. C#, asp.net 2.0 The following code supplies...
5
by: mcfly1204 | last post by:
I am attempting to use WebRequest to access a page that requires a login/password to access. My last WebRequest continues to timeout. Any help or thoughts would be appreciated. namespace...
1
by: prasadpanati | last post by:
Hi all, I a beginner in to asp.net and learning to use httpwebrequest. I am trying to login to orkut.com using the following code.... but unfortunatly i am unable to login to it Can some one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.