Imports Microsoft.VisualBasic
Imports System.Net

Public Class HTTPWebFormRequest

    Function sendHTTPPost(ByVal actionURL As String, ByVal formValuesInKeyValuePairs As String) As System.Net.WebResponse
        Try
            '##########################################################################################
            'MODIFICATION   ROD COPELAND    AUG 20, 2008   ISSUE 4454
            '##########################################################################################
            'WE NEED TO DO A FORM POST FROM THE SERVER TO THE BILL VENDOR SITE TO AUTHENTICATE, 
            'THEN WE REDIRECT THE USER TO THE BILL VENDOR DOMAIN.
            'THIS FUNCTION WAS INITIALLY CREATED TO MEET THIS NEED.
            'formValuesInKeyValuePairs example:
            'd=85F35CE3&k=&s=&successPage=currentstatement
            '##########################################################################################
            Dim encoding As New System.Text.ASCIIEncoding
            Dim data As Byte() = encoding.GetBytes(formValuesInKeyValuePairs)

            Dim MyRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(actionURL), System.Net.HttpWebRequest)
            MyRequest.Method = "POST"
            MyRequest.ContentType = "application/x-www-form-urlencoded"
            MyRequest.ContentLength = data.Length
            MyRequest.UserAgent = "Mozilla/4.0+"

            Dim newstream As System.IO.Stream = MyRequest.GetRequestStream
            newstream.Write(data, 0, data.Length)
            newstream.Close()

            Dim myResponse As WebResponse
            If Not (MyRequest Is Nothing) Then
                myResponse = MyRequest.GetResponse
                Return myResponse
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        End Try

    End Function


End Class
