954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

vb.net 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

jlego
Posting Pro
529 posts since Mar 2009
Reputation Points: 31
Solved Threads: 41
 

i've done an imageshack login and used webrequest
here's my code

Public Function im_login(ByVal pageUrl As String) As String
        Dim response As System.Net.WebResponse = Nothing

        Try
            '' Setup our Web request
            Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(pageUrl)


            '' Retrieve data from request
            response = request.GetResponse()

            Dim s As String
            Dim streamReceive As System.IO.Stream = response.GetResponseStream()
            Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
            Dim streamRead As System.IO.StreamReader = New System.IO.StreamReader(streamReceive, encoding)
            im_cookie = New CookieContainer

            If Not response.Headers.AllKeys.Contains("Set-Cookie") Then
                MsgBox("Login error, please check your account details", MsgBoxStyle.ApplicationModal)
                Invoke(inv2, Label2, "loginerr")
                Return " "
                Exit Function
            End If
            s = response.Headers.Item("Set-Cookie")
            Dim cookie As New Cookie
            cookie.Domain = ".imageshack.us"
            cookie.Path = "/"
            Dim temp As String = s.Substring(s.IndexOf("myid") + 5)
            Dim id As String = temp.Substring(0, temp.IndexOf(";"))
            cookie.Name = "myid"
            cookie.Value = id
            im_cookie.Add(cookie)

            cookie = New Cookie
            cookie.Domain = ".imageshack.us"
            cookie.Path = "/"

            temp = s.Substring(s.IndexOf("myimages") + 9)
            myimages = temp.Substring(0, temp.IndexOf(";"))
            cookie.Name = "myimages"
            cookie.Value = myimages
            im_cookie.Add(cookie)

            cookie = New Cookie
            cookie.Domain = ".imageshack.us"
            cookie.Path = "/"

            temp = s.Substring(s.IndexOf("isUSER") + 7)
            Dim isuser As String = temp.Substring(0, temp.IndexOf(";"))
            cookie.Name = "isUSER"
            cookie.Value = isuser
            im_cookie.Add(cookie)





            'mycookie.Add(c)


            Try

                Dim temp1 As String = s.Substring(s.IndexOf("isUSER") + 7)
                Dim us As String = temp1.Substring(0, temp1.IndexOf(";"))
                Invoke(inv2, Label2, "info" + us)
            Catch ex As Exception

            End Try



            Dim sr As String = streamRead.ReadToEnd()

            If sr = "OK" Then
                Invoke(inv2, Label2, "loggdin")
            Else : Invoke(inv2, Label2, "loginerr")
                MsgBox("There was an error, Please check your login details!", MsgBoxStyle.ApplicationModal)

            End If
            '' return the retrieved HTML
            Return streamRead.ReadToEnd()





        Catch ex As Exception
            log("HttpPage: " + ex.Message)
            Invoke(inv2, Label2, "loginerr")
            MsgBox("Connection Problem : " & vbCrLf + ex.Message, MsgBoxStyle.ApplicationModal)
            thread2.Abort()
        Finally
            ''Check if exists, then close the response.
            If Not response Is Nothing Then
                response.Close()
            End If

        End Try
        Return " "
    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

ÜnLoCo
Light Poster
40 posts since Dec 2009
Reputation Points: 10
Solved Threads: 8
 

i'll see what i can come up with. thanks.

jlego
Posting Pro
529 posts since Mar 2009
Reputation Points: 31
Solved Threads: 41
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("http://www.ritani.com/salespersons/login")
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        If WebBrowser1.Url.AbsoluteUri = "http://www.ritani.com/salespersons/login" Then
            WebBrowser1.Document.GetElementById("SalespersonEmail").SetAttribute("Value", "myCoolEmail@myCoolWebsite.com")
            WebBrowser1.Document.GetElementById("SalespersonPassword").SetAttribute("Value", "myCoolPassword")
            WebBrowser1.Document.Forms(1).InvokeMember("submit")
        End If

    End Sub

You might find this link useful.

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

i love you.

jlego
Posting Pro
529 posts since Mar 2009
Reputation Points: 31
Solved Threads: 41
 
i love you.


Does that mean we can make tons of webbrowsing vb.net babies?:D

Glad I could help.:)

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

ya all my vb6 babies are grown up i need some new ones.

hah.
thanks again

jlego
Posting Pro
529 posts since Mar 2009
Reputation Points: 31
Solved Threads: 41
 

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

<div class="module"> 
		<h2>Product Search</h2> 
		<form action="/products/search" method="post"> 
			<div> 
				<input name="data[Product][searchterm]"  size="25" value="" type="text" id="ProductSearchterm" />			</div> 
			<div> 
				<input type="submit" value="Search" />			</div> 
		</form> 
	</div>


my code:

Case Is = "http://www.ritani.com/products/search"
                Me.wbLookup.Document.GetElementById("ProductSearchterm").SetAttribute("Value", Me.strStyle$)
                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

:\

jlego
Posting Pro
529 posts since Mar 2009
Reputation Points: 31
Solved Threads: 41
 

here is the ritani search site

<div class="module"> 
		<h2>Product Search</h2> 
		<form action="/products/search" method="post"> 
			<div> 
				<input name="data[Product][searchterm]"  size="25" value="" type="text" id="ProductSearchterm" />			</div> 
			<div> 
				<input type="submit" value="Search" />			</div> 
		</form> 
	</div> 
	
		
	<h2>Product Search</h2> 
 
<form method="post" action="/products/search" > 
	<div> 
		<label for="ProductSearchterm">Enter search terms</label>		<input name="data[Product][searchterm]"  size="40" value="" type="text" id="ProductSearchterm" />	</div> 
	<div> 
		<input type="submit" value="Search" />	</div> 
</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

jlego
Posting Pro
529 posts since Mar 2009
Reputation Points: 31
Solved Threads: 41
 

figured it out, it was the first form with an index of 0 instead of 1. durh.

jlego
Posting Pro
529 posts since Mar 2009
Reputation Points: 31
Solved Threads: 41
 
figured it out, it was the first form with an index of 0 instead of 1. durh.


Glad the link I previously posted helped. :)

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: