942,967 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1217
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 8th, 2010
0

vb.net POST

Expand Post »
im going to try and explain this as easy as possible, this is something i have never done with .net before

there is a login form at http://www.ritani.com/salespersons/login
it uses the post method to login.

i have a web browser control in vb.net that I want to have automatically log in to the ritani website using the POST method instead of using send keys and tabbing etc.

is this possible? if so, can someone point me in the right direction. I have google it and havent really found anything i think relates to what i want to do, or i just dont understand it.

thanks
Similar Threads
Reputation Points: 31
Solved Threads: 40
Posting Pro
jlego is offline Offline
527 posts
since Mar 2009
Sep 8th, 2010
0
Re: vb.net POST
i've done an imageshack login and used webrequest
here's my code
VB.NET Syntax (Toggle Plain Text)
  1. Public Function im_login(ByVal pageUrl As String) As String
  2. Dim response As System.Net.WebResponse = Nothing
  3.  
  4. Try
  5. '' Setup our Web request
  6. Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(pageUrl)
  7.  
  8.  
  9. '' Retrieve data from request
  10. response = request.GetResponse()
  11.  
  12. Dim s As String
  13. Dim streamReceive As System.IO.Stream = response.GetResponseStream()
  14. Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
  15. Dim streamRead As System.IO.StreamReader = New System.IO.StreamReader(streamReceive, encoding)
  16. im_cookie = New CookieContainer
  17.  
  18. If Not response.Headers.AllKeys.Contains("Set-Cookie") Then
  19. MsgBox("Login error, please check your account details", MsgBoxStyle.ApplicationModal)
  20. Invoke(inv2, Label2, "loginerr")
  21. Return " "
  22. Exit Function
  23. End If
  24. s = response.Headers.Item("Set-Cookie")
  25. Dim cookie As New Cookie
  26. cookie.Domain = ".imageshack.us"
  27. cookie.Path = "/"
  28. Dim temp As String = s.Substring(s.IndexOf("myid") + 5)
  29. Dim id As String = temp.Substring(0, temp.IndexOf(";"))
  30. cookie.Name = "myid"
  31. cookie.Value = id
  32. im_cookie.Add(cookie)
  33.  
  34. cookie = New Cookie
  35. cookie.Domain = ".imageshack.us"
  36. cookie.Path = "/"
  37.  
  38. temp = s.Substring(s.IndexOf("myimages") + 9)
  39. myimages = temp.Substring(0, temp.IndexOf(";"))
  40. cookie.Name = "myimages"
  41. cookie.Value = myimages
  42. im_cookie.Add(cookie)
  43.  
  44. cookie = New Cookie
  45. cookie.Domain = ".imageshack.us"
  46. cookie.Path = "/"
  47.  
  48. temp = s.Substring(s.IndexOf("isUSER") + 7)
  49. Dim isuser As String = temp.Substring(0, temp.IndexOf(";"))
  50. cookie.Name = "isUSER"
  51. cookie.Value = isuser
  52. im_cookie.Add(cookie)
  53.  
  54.  
  55.  
  56.  
  57.  
  58. 'mycookie.Add(c)
  59.  
  60.  
  61. Try
  62.  
  63. Dim temp1 As String = s.Substring(s.IndexOf("isUSER") + 7)
  64. Dim us As String = temp1.Substring(0, temp1.IndexOf(";"))
  65. Invoke(inv2, Label2, "info" + us)
  66. Catch ex As Exception
  67.  
  68. End Try
  69.  
  70.  
  71.  
  72. Dim sr As String = streamRead.ReadToEnd()
  73.  
  74. If sr = "OK" Then
  75. Invoke(inv2, Label2, "loggdin")
  76. Else : Invoke(inv2, Label2, "loginerr")
  77. MsgBox("There was an error, Please check your login details!", MsgBoxStyle.ApplicationModal)
  78.  
  79. End If
  80. '' return the retrieved HTML
  81. Return streamRead.ReadToEnd()
  82.  
  83.  
  84.  
  85.  
  86.  
  87. Catch ex As Exception
  88. log("HttpPage: " + ex.Message)
  89. Invoke(inv2, Label2, "loginerr")
  90. MsgBox("Connection Problem : " & vbCrLf + ex.Message, MsgBoxStyle.ApplicationModal)
  91. thread2.Abort()
  92. Finally
  93. ''Check if exists, then close the response.
  94. If Not response Is Nothing Then
  95. response.Close()
  96. End If
  97.  
  98. End Try
  99. Return " "
  100. End Function

now you have to examine the ritani login with firebug for example and get the post params used as well as the structure of the cookies that are set.
www.getfirebug.com
Firecookie :: Add-ons for Firefox
Reputation Points: 10
Solved Threads: 8
Light Poster
ÜnLoCo is offline Offline
40 posts
since Dec 2009
Sep 9th, 2010
0
Re: vb.net POST
i'll see what i can come up with. thanks.
Reputation Points: 31
Solved Threads: 40
Posting Pro
jlego is offline Offline
527 posts
since Mar 2009
Sep 9th, 2010
1
Re: vb.net POST
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. WebBrowser1.Navigate("http://www.ritani.com/salespersons/login")
  3. End Sub
  4.  
  5. Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
  6.  
  7. If WebBrowser1.Url.AbsoluteUri = "http://www.ritani.com/salespersons/login" Then
  8. WebBrowser1.Document.GetElementById("SalespersonEmail").SetAttribute("Value", "myCoolEmail@myCoolWebsite.com")
  9. WebBrowser1.Document.GetElementById("SalespersonPassword").SetAttribute("Value", "myCoolPassword")
  10. WebBrowser1.Document.Forms(1).InvokeMember("submit")
  11. End If
  12.  
  13. End Sub
You might find this link useful.
Reputation Points: 234
Solved Threads: 358
Nearly a Posting Virtuoso
codeorder is offline Offline
1,382 posts
since Aug 2010
Sep 9th, 2010
0
Re: vb.net POST
i love you.
Reputation Points: 31
Solved Threads: 40
Posting Pro
jlego is offline Offline
527 posts
since Mar 2009
Sep 9th, 2010
0
Re: vb.net POST
Click to Expand / Collapse  Quote originally posted by jlego ...
i love you.
Does that mean we can make tons of webbrowsing vb.net babies?

Glad I could help.
Reputation Points: 234
Solved Threads: 358
Nearly a Posting Virtuoso
codeorder is offline Offline
1,382 posts
since Aug 2010
Sep 9th, 2010
0
Re: vb.net POST
ya all my vb6 babies are grown up i need some new ones.

hah.
thanks again
Reputation Points: 31
Solved Threads: 40
Posting Pro
jlego is offline Offline
527 posts
since Mar 2009
Sep 9th, 2010
0
Re: vb.net POST
hey here is another question
your code worked flawless, and i moved on to the next page which i have a search form

input box and a submit button

VB.NET Syntax (Toggle Plain Text)
  1. <div class="module">
  2. <h2>Product Search</h2>
  3. <form action="/products/search" method="post">
  4. <div>
  5. <input name="data[Product][searchterm]" size="25" value="" type="text" id="ProductSearchterm" /> </div>
  6. <div>
  7. <input type="submit" value="Search" /> </div>
  8. </form>
  9. </div>

my code:

VB.NET Syntax (Toggle Plain Text)
  1. Case Is = "http://www.ritani.com/products/search"
  2. Me.wbLookup.Document.GetElementById("ProductSearchterm").SetAttribute("Value", Me.strStyle$)
  3. Me.wbLookup.Document.Forms(1).InvokeMember("Search")

its the first form on the site but nothing is happening. filling in the input box thats all

:\
Reputation Points: 31
Solved Threads: 40
Posting Pro
jlego is offline Offline
527 posts
since Mar 2009
Sep 9th, 2010
0
Re: vb.net POST
here is the ritani search site

VB.NET Syntax (Toggle Plain Text)
  1. <div class="module">
  2. <h2>Product Search</h2>
  3. <form action="/products/search" method="post">
  4. <div>
  5. <input name="data[Product][searchterm]" size="25" value="" type="text" id="ProductSearchterm" /> </div>
  6. <div>
  7. <input type="submit" value="Search" /> </div>
  8. </form>
  9. </div>
  10.  
  11.  
  12. <h2>Product Search</h2>
  13.  
  14. <form method="post" action="/products/search" >
  15. <div>
  16. <label for="ProductSearchterm">Enter search terms</label> <input name="data[Product][searchterm]" size="40" value="" type="text" id="ProductSearchterm" /> </div>
  17. <div>
  18. <input type="submit" value="Search" /> </div>
  19. </form>

there is two forms. i want it to use the second form, but the first will work as well. but it isnt finding the submit button on either. i tried a few different things and nothing is working
Reputation Points: 31
Solved Threads: 40
Posting Pro
jlego is offline Offline
527 posts
since Mar 2009
Sep 9th, 2010
0
Re: vb.net POST
figured it out, it was the first form with an index of 0 instead of 1. durh.
Reputation Points: 31
Solved Threads: 40
Posting Pro
jlego is offline Offline
527 posts
since Mar 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: get icon of webpage
Next Thread in VB.NET Forum Timeline: What's wrong with this code? Runs too slow!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC