Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

Using http post in vb code behind

I have a web site that allows users to pay on line.   I signed up for a service that would check the routing number to make sure it was valid before continuing.  They provided me the code below to use to test the routing number.,  My problem is I use vb code behind and dont want to use a seperate form to test the routing number, I want to make it part of the process of making a payment with my vb code behind.  Can someone tell me how to do that.

thanks

<html>
<head>
<title>RoutingTool Verification Form (sample)</title>
<link rel="stylesheet" type="text/css" href="http://secure.routingtool.com/styles/rt.css">
</head>
<body>
<form method="post" action="https://secure.routingtool.com/cgi-bin/weblink.cgi" name="weblink">
<input type="hidden" name="weblinkagentid" value="74305">
<input type="hidden" name="weblinkid" value="">
<input type="hidden" name="resultformat" value="xml">
<input type="hidden" name="user1" value="userdefined1">
<input type="hidden" name="user2" value="userdefined2">

<!-- Other result formats avail: text, xml, html

  <input type="hidden" name="resultformat" value="html">
  <input type="hidden" name="resultformat" value="text">

-->
<table border="0" cellpadding="2" cellspacing="1" width="300">
<tr>
<td><font face="Verdana" color="#000000" size="1">
9 Digit Routing #:
</font>
</td>
<td>
<input type="text" name="routing"  size="20"/>
</td>
</tr>
</table>
<p />
<input type="hidden" name="op" value="process" />
<input type="submit" name="submit" value="Next &gt;&gt; " />
<hr>
<p align="center">
<font face="Verdana" color="#F41200" size="1">RoutingTool&#153; is a trademark
of yourfavorite.com. 
<br />
&copy;Copyright 2005 yourfavorite.com, All rights reserved.
</font>
</p>
</body>
</html>

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

What does the service return to you? HTML? A string indicating success or failure? Something else? How would you code know from the response whether the tool indicated success or failure?
Avatar of mgmhicks
mgmhicks

ASKER

<input type="hidden" name="resultformat" value="xml">

<!-- Other result formats avail: text, xml, html

  <input type="hidden" name="resultformat" value="html">
  <input type="hidden" name="resultformat" value="text">
Then you should be able to do something like:

Using client As New System.Net.WebClient()
    Dim data As New System.Collections.Specialized.NameValueCollection()

    data.Add("weblinkagentid", "74305")
    data.Add("weblinkid", "")
    data.Add("resultformat", "xml")
    data.Add("user1", "userdefined1")
    data.Add("user2", "userdefined2")
    data.Add("routing", your_routing_number)

    Dim responseData() As Byte = client.UploadValues("https://secure.routingtool.com/cgi-bin/weblink.cgi", data)
    Dim xml As String = Text.Encoding.ASCII.GetString(responseData)
    Dim xdoc As New Xml.XmlDocument()
    Dim resultNode As Xml.XmlNode

    xdoc.LoadXml(xml)

    resultNode = xdoc.SelectSingleNode("/xpath/to/the/result/node")

    If resultNode IsNot Nothing Then
        ' do something with result
    End If

End Using

Open in new window


You may need to add in a XmlNamespaceManager if the returned XML has any namespaces defined within it.
I think we are on to something.  Here is my code, when I run it I get an exception on the loadxml line,  "Data at the root level is invalid.  Line 1, position 1.  Any ideas

Try
            Using client As New System.Net.WebClient()
                Dim data As New System.Collections.Specialized.NameValueCollection()

                data.Add("weblinkagentid", "21554")
                data.Add("weblinkid", "Password")
                data.Add("resultformat", "xml")
                data.Add("user1", "userdefined1")
                data.Add("user2", "userdefined2")
                data.Add("routing", TextBox1.Text)

                Dim responseData() As Byte = client.UploadValues("https://secure.routingtool.com/cgi-bin/weblink.cgi", data)
                Dim xml As String = Text.Encoding.ASCII.GetString(responseData)
                Dim xdoc As New System.Xml.XmlDocument()
                Dim resultNode As System.Xml.XmlNode

                xdoc.LoadXml(xml)

                resultNode = xdoc.SelectSingleNode("/xpath/to/the/result/node")

                If resultNode IsNot Nothing Then
                    ' do something with result
                End If

            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Open in new window

Put a breakpoint on line 17. When it is hit, mouse over "xml" and see what it contains.
here is what is in xml

"Unauthorized<br />Referrer: "

Now I had to setup a referr from where the post will come from, testing on a local host, what http reference would I send, our external ip address.

How can I tell what the local host they are receiving from the post is?

thank you again
A referrer is the URL that made the request to the external page. In your original sample, the referrer would have been that page. You might try putting in the full URL of the original page that you were using when first started all of this.
So if I am doing it from localhost would it be http://myipaddress/something.html

thanks
So I set the reference to http://localhost:59374/ResidentPortal052013/Administration/RoutingTest.aspx

That is the address that comes up when I run locally.  Still receiving same error.  Been waiting all day for the company to get back to me.  RoutingTool
I wonder if it's the Referrer field that's actually causing the problem. The <br/> in that statement denotes a line break, so maybe the error message is simply "Unauthorized" and the Referrer part is just informational. Are you certain you are using the credentials provided to you by the service?
You may be right, I changed the password and userid and received the same error.  I am sure those are correct, I can get on site with them, so you may be right about the <br>
Did you have to enter any details about your site or the page that would be making the calls when you signed up for the service? Perhaps if you did, then whatever you entered there is what you need to use.
According to the service provider each language has its own way of setting the referrer.  So what I need to be able to do is change the posting referrer in my code to match what I said it would be on their web site.  So how do we change the referrer of the  client object?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
receiving error "Property access must assing to the property or use its value."

with line


client.Headers("Referrer", "http://your.site.com/path/to/page.aspx")
Heheh. My screen is too dark. I didn't see the blue squiggly  = )

Corrected:

client.Headers("Referrer") = "http://your.site.com/path/to/page.aspx"

Open in new window

here is the link to set this up

https://secure.routingtool.com/cgi-bin/controlpanel.cgi?op=weblink

I would like to get you and just you the userid and password so you can test it out as well.  We are still getting same error.  Can I send you private message?  

Code I am using is below



  Try
            Using client As New System.Net.WebClient()
                Dim data As New System.Collections.Specialized.NameValueCollection()
                '  data.Add("referrer", "http://localhost:59374/ResidentPortal052013/Administration/RoutingTest.aspx")
                data.Add("weblinkagentid", "74305")
                data.Add("weblinkid", "mySecure")
                data.Add("resultformat", "xml")
                data.Add("user1", "userdefined1")
                data.Add("user2", "userdefined2")
                data.Add("routing", TextBox1.Text)


                client.Headers.Add("Referrer", "http://localhost:59374/ResidentPortal052013/Administration/RoutingTest.aspx")

                client.Headers("Referrer") = "http://localhost:59374/ResidentPortal052013/Administration/RoutingTest.aspx"

                Dim responseData() As Byte = client.UploadValues("https://secure.routingtool.com/cgi-bin/weblink.cgi", data)
                Dim xml As String = Text.Encoding.ASCII.GetString(responseData)
                Dim xdoc As New System.Xml.XmlDocument()
                Dim resultNode As System.Xml.XmlNode

                xdoc.LoadXml(xml)

                resultNode = xdoc.SelectSingleNode("/xpath/to/the/result/node")
                MsgBox(resultNode)
                If resultNode IsNot Nothing Then
                    ' do something with result
                End If

            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Open in new window

OK, so at this point I think it's going to be something that you'll need to work out with RoutingTool's support section.
this is what I beleive we are looking for, the rest is up to the vendor.

thank you