Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WEB Form POST in code behind

Posted on 2009-05-06
3
Medium Priority
?
1,027 Views
Last Modified: 2013-11-26
How would I accomplish this in vb code behind?


<form name="DateSelect" runat="server" action="http://www.domaincom/reserve.php" method="POST" target="_self">
<input type="hidden" name="cust_memberid" value="EX80000">

---MORE HIDDEN INPUTS-----
<input id="Submit1" type="submit"
    value="submit" OnClick="return checkDates(this.form)"/>
</form>



I have the code below and need to modify the second sub to get the post back with however the "return checkDates..."  is working


....blah...blah...blah...
 
_wXML &= "<input type=""hidden"" name=""numrooms"" value=""2"">"
_wXML &= "<input type=""hidden"" name=""sh"" value=""yes"">"
_wXML &= "<input type=""hidden"" name=""lang"" value=""en"">"
_wXML &= "<input type=""hidden"" name=""grp"" value=""exotictrav"">"
 
 GetReservationsInventory("http://www.reservationdomain.com/reserve.php", _wXML)
 
 
Public Sub GetReservationsInventory(ByVal URI As String, ByVal Parameters As String)
        Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(URI)
 
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim ds As DataSet
 
        Try
            ' Create the web request   
            request = DirectCast(WebRequest.Create(URI), HttpWebRequest)
            request.ContentType = "application/x-www-form-urlencoded"
            request.Method = "POST"
 
 
           
            ' Get response   
            response = ----WHAT?----
           
        Finally
            If Not response Is Nothing Then response.Close()
        End Try
 
    End Sub

Open in new window

0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:tillgeffken
ID: 24314944
Your going down the wrong road my friend. Posting data to that server is not as trivial as that. I'm a C# programmer so i can't guarantee this is working code but should get you the idea. (Modified MSDN example code)

Dim MyPostData As String = "numrooms=2&sh=yes&lang=en&group=exotictrav"
Dim MyUrl As String = "http://www.reservationdomain.com/reserve.php"
FetchData(MyUrl, MyPostData)
 
 
        Public Sub FetchData(ByVal URI As String, ByVal PostData As String)
            ' Create a request using a URL that can receive a post. 
            Dim request As WebRequest = WebRequest.Create(URI)
            ' Set the Method property of the request to POST.
            request.Method = "POST"
            ' Create POST data and convert it to a byte array.
            Dim postData As String = PostData 
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
            ' Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded"
            ' Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length
            ' Get the request stream.
            Dim dataStream As Stream = request.GetRequestStream()
            ' Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length)
            ' Close the Stream object.
            dataStream.Close()
            ' Get the response.
            Dim response As WebResponse = request.GetResponse()
            ' Display the status.
            Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
            ' Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Do something with the response here.
 
            reader.Close()
            dataStream.Close()
            response.Close()
        End Sub

Open in new window

0
 

Author Comment

by:lrbrister
ID: 24315194
tillgeffken:
When I run this post in regular HTML it posts to the remote domain...which then does it's own thing and a redirect to it's processing page.

The submit buttom looks like this...
<input type="submit" name="availcheck" value="Submit" onClick="return checkDates(this.form)">
0
 

Accepted Solution

by:
lrbrister earned 0 total points
ID: 24316787
I found my own workaround by placing the _wXML as a variable in a form and doing  a form post on page load

<body onload='Javascript: document.forms[0].submit();'>

<form name="Form1" id="Form1" runat="server" action="http://www.doamin.com/reserve.php" method="POST" target="_self">
<%=PlayerScript%>
  ---LOADING---
    </form>  
</body>
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question