I am setting up a shopping cart using foxycart and asp.net(vb)
FoxyCart sends me an xml feed by a httprequest (RC4 encrypted and URLEncoded)
In order to test my receiver page (datareturn.aspx) I have created a sample test page in vb (sampledata.aspx) based on their own c# version. This loads data from a sample xml file (sampledata.xml)
The problem is no post data is received at datareturn.aspx. I know this as the following is written to the file datafeed.xml:
Request.Form.Count = 0. There was nothing in the forms collection - The Request Method was GET
It appears that the request mehtod came through as GET not POST. Any one any ideas?
The sampledata.aspx is as follows:
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Web
Partial Class sampledata
Inherits System.Web.UI.Page
Private Shared DataFeedKey As String = "LkVjnPFIE8SZHSkRvSmLpmXl2ZvASNjvY5IhNeQigDcSqmALaRnt8fE154vM"
Sub Main()
'Load data
Dim cartData As String = (New StreamReader(Server.MapPath("SampleData.xml"))).ReadToEnd()
Dim encCartData As String
'Encrypt, then URL encode
Dim RC4 As RC4 = New RC4
encCartData = RC4.Encrypt(DataFeedKey, cartData, False)
Dim postData As String = "FoxyData=" & HttpUtility.UrlEncode(encCartData)
'Create a web request to send the data
Dim req As HttpWebRequest = CType(WebRequest.Create("http://foxycart.mrtaxsoftware.com/datareturn.aspx"), HttpWebRequest)
req.Method = "post"
req.ContentType = "application/x-www-form-urlencoded"
'Write POST stream
Dim sw As New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
sw.Write(New ASCIIEncoding().GetBytes(postData))
sw.Flush()
sw.Close()
'Send it and see if it was okay
Dim resp As HttpWebResponse = Nothing
Try
resp = CType(req.GetResponse(), HttpWebResponse)
Response.Write(resp.StatusCode & " " & resp.StatusDescription)
Catch ex As WebException
Dim err As String = New StreamReader(ex.Response.GetResponseStream()).ReadToEnd()
End Try
End Sub
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Main()
End Sub
End Class
The datareturn.aspx file is as follows:
Imports System.IO
Public Class datareturn
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TheRealThing()
End Sub
Private Sub TheRealThing()
'
'Real Code to handle htppRequests
'
Dim Stream As System.IO.Stream = Request.InputStream
Dim strLen As Integer = CInt(Stream.Length)
Dim buffer As Byte() = New Byte(strLen) {}
Stream.Read(buffer, 0, strLen)
'test data to file
'Open a file for recording information
'Open a file
'Get a StreamWriter class that can be used to write to the file
Dim Filename As String = Server.MapPath("datafeed.xml")
Dim objStreamWriter As StreamWriter
objStreamWriter = File.CreateText(Filename)
If Request.Form.Count <> 0 Then
Dim FoxyFeed As String = Request.Form("FoxyData")
Dim ff_bytes As Byte() = Encoding.ASCII.GetBytes(FoxyFeed)
Dim FoxyData As String = HttpUtility.UrlDecode(ff_bytes, Encoding.GetEncoding(0)) ' Server.UrlDecode(FoxyFeed)
Dim RC4 As RC4 = New RC4
Dim FoxyData_decrypted As String
Try
FoxyData_decrypted = RC4.Decrypt(System.Configuration.ConfigurationManager.AppSettings("FoxyCartKey"), FoxyData, False)
Catch ex As Exception
Throw New Exception("RC4 decrypting error: " + ex.Message)
Finally
RC4 = Nothing
End Try
objStreamWriter.Write("FoxyData Decrypted = " & FoxyData_decrypted)
Response.Write("foxy")
Response.End()
Else
objStreamWriter.Write("Request.Form.Count = 0. There was nothing in the forms collection - The Request Method was " & Request.RequestType)
End If
'Close the stream
objStreamWriter.Close()
objStreamWriter.Dispose()
End Sub
End Class