Public Class FormPOST
Private Sub ButtonShazam_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonShazam.Click
'Create a variable to hold the product name and version
Dim productNameVersion As String =
My.Application.Info.ProductName & " " &
My.Application.Info.Version.ToString
'Configure the transaction type
Dim TranType As String = "CreditTransaction"
'Build the XML Request
Dim TranCommand As String = "<?xml version=""1.0""?>" & vbCrLf
& "<TStream>" & vbCrLf & " <Transaction>" & vbCrLf & "
<MerchantID>" & "595901" & "</MerchantID>" & vbCrLf & "
<TranType>Credit</TranType>" & vbCrLf & " <TranCode>Sale</
TranCode>" & vbCrLf & " <InvoiceNo>" & "1" & "</InvoiceNo>" &
vbCrLf & " <RefNo>" & "1" & "</RefNo>" & vbCrLf &
" <Memo>" & productNameVersion & "</Memo>" & vbCrLf &
" <Account>" & vbCrLf & " <Track2>" &
"4003000123456781=09085025432198712345" & "</Track2>" & vbCrLf &
" </Account>" & vbCrLf & " <Amount>" & vbCrLf &
" <Purchase>" & "1.23" & "</Purchase>" & vbCrLf &
" </Amount>" & vbCrLf & " </Transaction>" & vbCrLf & "</
TStream>"
'Replace < and > symbols so our web services platform doesn't
throw errors
TranCommand = TranCommand.Replace("<", "<")
TranCommand = TranCommand.Replace(">", ">")
'Set a variable with the POST data
Dim postData As String = "<?xml version=""1.0""
encoding=""utf-8""?>" & vbCrLf & "<soap:Envelope xmlns:soap=""http://
schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/
2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/
XMLSchema"">" & vbCrLf & vbCrLf & "<soap:Body>" & vbCrLf & " <" &
TranType & " xmlns=""http://www.mercurypay.com"">" & vbCrLf &
" <tran>" & TranCommand & "</tran>" & vbCrLf & "
<pw>" & "xyz" & "</pw>" & vbCrLf & " </" & TranType & ">" &
vbCrLf & "</soap:Body>" & vbCrLf & vbCrLf & "</soap:Envelope>"
'Create the Web Request and assign it the requestUriString
Dim myWebRequest As System.Net.HttpWebRequest =
System.Net.WebRequest.Create("https://" & "w1.mercurydev.net" & "/ws/
ws.asmx")
'Set the Method header to POST
myWebRequest.Method = "POST"
'Set the User-Agent header to the productNameVersion
myWebRequest.UserAgent = productNameVersion
'Set the content type header
myWebRequest.ContentType = "text/xml; charset=utf-8"
'Create a custom header called SOAPAction and set the value
myWebRequest.Headers.Add("SOAPAction", "http://
www.mercurypay.com/" & TranType)
'Set the Web Request length values
myWebRequest.ContentLength =
System.Text.Encoding.ASCII.GetBytes(postData).Length
'Create a stream and run the POST
Dim outputStream As System.IO.Stream =
myWebRequest.GetRequestStream()
outputStream.Write(System.Text.Encoding.ASCII.GetBytes(postData), 0,
System.Text.Encoding.ASCII.GetBytes(postData).Length)
outputStream.Close()
'Read the response
Try
Dim responseStream As System.IO.Stream =
myWebRequest.GetResponse().GetResponseStream()
Dim theresponse As System.Net.HttpWebResponse =
DirectCast(myWebRequest.GetResponse(), System.Net.HttpWebResponse)
Dim reader As New
System.IO.StreamReader(theresponse.GetResponseStream())
TextBoxResults.Text = reader.ReadToEnd
'If there's an error, catch it and show it
Catch f As Exception
TextBoxResults.Text = f.Message
End Try
End Sub
Private Sub ButtonCleanup_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonCleanup.Click
'Get back the < and > symbols
TextBoxResults.Text = TextBoxResults.Text.Replace("<", "<")
TextBoxResults.Text = TextBoxResults.Text.Replace(">", ">")
End Sub
End Class