I'm trying to set up code to accept credit cards, submit them to a processing gateway, then receive feedback from the gateway.

I received sample code from the gateway company. But when I put the sample page on my ISP's server, I get the following error:

"Object reference not set to an instance of an object"

and it points to the line of code that closes the request streamwriter:


Here's the full code:

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_Load(Src As [Object], E As EventArgs)
myPage.Text = readHtmlPage("https://test.mygateway.net/gateway/transact.dll")
'Uncomment the line ABOVE for shopping cart testing OR uncomment the line BELOW for live accounts
'myPage.Text = readHtmlPage("https://secure.mygateway.net/gateway/transact.dll")
End Sub 'Page_Load

Private Function readHtmlPage(url As String) As [String]
Dim result As [String] = ""
Dim strPost As [String] = "x_login=YOUR-LOGIN-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=052009&x_test_request=TRUE&x_versio n=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"

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

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

' Close and clean up the StreamReader
Return result
End Function 'readHtmlPage
<b>The content on this web page is the result of an HTTP POST operation to Authorize.Net, using the Advanced Implementation method (AIM).<br>
<asp:literal id="myPage" runat="server"/>

Anyone know what the problem here is?