471,086 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Posting login data with HttpWebRequest

Hello. Have been losing plenty of hair over problem whereby I can't
make it off the login page. Trying to pass login info to a login page
and then move on to another page within the site so that I can download
some data, but I keep getting the login page.
Any ideas on this?

Here's the code:
==================================================

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim httpRequest As HttpWebRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/"), HttpWebRequest)
Dim responseReader As StreamReader = New
StreamReader(httpRequest.GetResponse.GetResponseSt ream)
Dim responseData As String = responseReader.ReadToEnd
responseReader.Close()

Dim viewState As String = ExtractViewState(responseData)
Dim postData As String =
"iDirectLogin_userID=USERID&iDirectLogin_userPass= PASSWORD"

Dim cookies As CookieContainer = New CookieContainer

httpRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/"), HttpWebRequest)
httpRequest.Method = "POST"
httpRequest.KeepAlive = True
httpRequest.Timeout = 120 * 1000
httpRequest.ContentType = "application/x-www-form-urlencoded"
httpRequest.CookieContainer = cookies

Dim requestWriter As StreamWriter = New
StreamWriter(httpRequest.GetRequestStream)
requestWriter.Write(postData)
requestWriter.Close()

httpRequest.GetResponse.Close()

httpRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/search.aspx"),
HttpWebRequest)
httpRequest.CookieContainer = cookies
responseReader = New
StreamReader(httpRequest.GetResponse.GetResponseSt ream)
' and read the response
responseData = responseReader.ReadToEnd
responseReader.Close()
Response.Write(responseData)

End Sub
==================================

Here's what's in the form:
<input name="iDirectLogin:userID" type="text" id="iDirectLogin_userID"
style="width:100px;WIDTH: 100px" /></td>
<input name="iDirectLogin:userPass" type="password"
id="iDirectLogin_userPass" style="width:100px;WIDTH: 100px" /></td>
<input type="submit" name="iDirectLogin:btnLogIn" value="Log-In"
id="iDirectLogin_btnLogIn" class="button" style="width:80px;" />
Any help would be greatly appreciated.
Regards,

adwooley2

Sep 27 '06 #1
2 5459
Hello adwooley2,
Hello. Have been losing plenty of hair over problem whereby I can't
make it off the login page. Trying to pass login info to a login page
and then move on to another page within the site so that I can
download
some data, but I keep getting the login page.
Any ideas on this?
Here's the code:
==================================================
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim httpRequest As HttpWebRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/"), HttpWebRequest)
Dim responseReader As StreamReader = New
StreamReader(httpRequest.GetResponse.GetResponseSt ream)
Dim responseData As String = responseReader.ReadToEnd
responseReader.Close()
Dim viewState As String = ExtractViewState(responseData)
Dim postData As String =
"iDirectLogin_userID=USERID&iDirectLogin_userPass= PASSWORD"
Dim cookies As CookieContainer = New CookieContainer

httpRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/"), HttpWebRequest)
httpRequest.Method = "POST"
httpRequest.KeepAlive = True
httpRequest.Timeout = 120 * 1000
httpRequest.ContentType = "application/x-www-form-urlencoded"
httpRequest.CookieContainer = cookies
Dim requestWriter As StreamWriter = New
StreamWriter(httpRequest.GetRequestStream)
requestWriter.Write(postData)
requestWriter.Close()
httpRequest.GetResponse.Close()

httpRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/search.aspx"),
HttpWebRequest)
httpRequest.CookieContainer = cookies
responseReader = New
StreamReader(httpRequest.GetResponse.GetResponseSt ream)
' and read the response
responseData = responseReader.ReadToEnd
responseReader.Close()
Response.Write(responseData)
End Sub
==================================
Here's what's in the form:
<input name="iDirectLogin:userID" type="text" id="iDirectLogin_userID"
style="width:100px;WIDTH: 100px" /></td>
<input name="iDirectLogin:userPass" type="password"
id="iDirectLogin_userPass" style="width:100px;WIDTH: 100px" /></td>
<input type="submit" name="iDirectLogin:btnLogIn" value="Log-In"
id="iDirectLogin_btnLogIn" class="button" style="width:80px;" />
Any help would be greatly appreciated. Regards,
It sounds like you are not persisting the principal 's token in the cookies
for the subsequent request. I'm not sure I can help much, but just wanted
to say I love your username ;)

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Sep 28 '06 #2
Thanks Jim. Not sure where I'll go with this, but appreciate the
reply.
Yes, nice name indeed. I live in Japan currently, and the
pronunciation of my last name always trips up the Japanese.

Rgds,
adwooley2
Jim Wooley wrote:
Hello adwooley2,
Hello. Have been losing plenty of hair over problem whereby I can't
make it off the login page. Trying to pass login info to a login page
and then move on to another page within the site so that I can
download
some data, but I keep getting the login page.
Any ideas on this?
Here's the code:
==================================================
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim httpRequest As HttpWebRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/"), HttpWebRequest)
Dim responseReader As StreamReader = New
StreamReader(httpRequest.GetResponse.GetResponseSt ream)
Dim responseData As String = responseReader.ReadToEnd
responseReader.Close()
Dim viewState As String = ExtractViewState(responseData)
Dim postData As String =
"iDirectLogin_userID=USERID&iDirectLogin_userPass= PASSWORD"
Dim cookies As CookieContainer = New CookieContainer

httpRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/"), HttpWebRequest)
httpRequest.Method = "POST"
httpRequest.KeepAlive = True
httpRequest.Timeout = 120 * 1000
httpRequest.ContentType = "application/x-www-form-urlencoded"
httpRequest.CookieContainer = cookies
Dim requestWriter As StreamWriter = New
StreamWriter(httpRequest.GetRequestStream)
requestWriter.Write(postData)
requestWriter.Close()
httpRequest.GetResponse.Close()

httpRequest =
CType(WebRequest.Create("http://www.idirect.co.jp/search.aspx"),
HttpWebRequest)
httpRequest.CookieContainer = cookies
responseReader = New
StreamReader(httpRequest.GetResponse.GetResponseSt ream)
' and read the response
responseData = responseReader.ReadToEnd
responseReader.Close()
Response.Write(responseData)
End Sub
==================================
Here's what's in the form:
<input name="iDirectLogin:userID" type="text" id="iDirectLogin_userID"
style="width:100px;WIDTH: 100px" /></td>
<input name="iDirectLogin:userPass" type="password"
id="iDirectLogin_userPass" style="width:100px;WIDTH: 100px" /></td>
<input type="submit" name="iDirectLogin:btnLogIn" value="Log-In"
id="iDirectLogin_btnLogIn" class="button" style="width:80px;" />
Any help would be greatly appreciated. Regards,

It sounds like you are not persisting the principal 's token in the cookies
for the subsequent request. I'm not sure I can help much, but just wanted
to say I love your username ;)

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Sep 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by love_norip | last post: by
9 posts views Thread by buran | last post: by
14 posts views Thread by n8 | last post: by
8 posts views Thread by shankararaman.s | last post: by
reply views Thread by msnews.microsoft.com | last post: by

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.