converting to vb.net from c#.net authorize.net

authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net 

<code><%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E) {
myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll");
}
private String readHtmlPage(string url)
{
String result = "";
String strPost = "x_login=YOUR-LOG-IN-ID&x_tran_key=YOUR-TRANSACTION-KEY&x_method=CC&x_type=AUTH_CAPTURE&x_amount=1.00&x_delim_data=TRUE&x_delim_char=|&x_relay_response=FALSE&x_card_num=4111111111111111&x_exp_date=052005&x_test_request=TRUE&x_version=3.1";
StreamWriter myWriter = null;

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";

try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally {
myWriter.Close();
}

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
</script>
<html>
<body>
The content on this web page is the result of an HTTP POST operation to Authorize.Net, using the Advanced Implementation method (AIM).<br>

<hr/>
<asp:literal id="myPage" runat="server"/>
</body>
</html>
</cobe>
0
TorontoVB
4/19/2004 6:01:59 PM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 4 followers.

💬 2 Replies
👁️‍🗨️ 7441 Views


The main body of code is here:


Private Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)
myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll")
End Sub

Private Function readHtmlPage(ByVal url As String) As String
Dim result As String = ""
Dim strPost As String = "x_login=YOUR-LOG-IN-ID&x_tran_key=YOUR-TRANSACTION-KEY&x_method=CC&x_type=AUTH_CAPTURE&x_amount=1.00&x_delim_data=TRUE&x_delim_char=|&x_relay_response=FALSE&x_card_num=4111111111111111&x_exp_date=052005&x_test_request=TRUE&x_version=3.1"
Dim myWriter As StreamWriter = Nothing

Dim objRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentLength = strPost.Length
objRequest.ContentType = "application/x-www-form-urlencoded"

Try
myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(strPost)
Catch e As Exception
Return e.Message
Finally
myWriter.Close()
End Try

Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
Imports (StreamReader sr =
Shadows Function)() As StreamReader(objResponse.GetResponseStream())
result = sr.ReadToEnd()

' Close and clean up the StreamReader
sr.Close()
End Function
Return result
End Function

Darrell Norton, MVP
Darrell Norton's Blog


Please mark this post as answered if it helped you!
0
DarrellNorton
4/19/2004 7:10:16 PM
whenever I Compile that I am getting a syntax error 

Compiler Error Message: BC30035: Syntax error.
Source Error:

Line 26:
Line 27: Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
Line 28: Imports (sr =
Line 29: Shadows Function)() As StreamReader(objResponse.GetResponseStream())

0
TorontoVB
4/19/2004 9:01:41 PM
Reply: