Anyone using PayPal IPN with .NET?

G

Greg

I have code (below) that was working a year ago that I'm trying to use again
and it's now not working. The response is always invalid. Anyone know why?

Code:

Function GetPayPal() As Boolean
Dim myRequest As HttpWebRequest =
CType(HttpWebRequest.Create("https://www.paypal.com/cgi-bin/webscr"),
HttpWebRequest)
Dim strToSend As String
myRequest.AllowAutoRedirect = False
myRequest.Method = "POST"
myRequest.ContentType = "application/x-www-form-urlencoded"

strToSend = Request.Form.ToString()
'Create the string to post back to PayPal system to validate
strToSend &= "&cmd=_notify-validate"

'Create post stream
Dim RequestStream As Stream = myRequest.GetRequestStream()
Dim SomeBytes() As Byte = Encoding.UTF8.GetBytes(strToSend)

RequestStream.Write(SomeBytes, 0, SomeBytes.Length)
RequestStream.Close()

'Send request and get response
Dim myResponse As HttpWebResponse = CType(myRequest.GetResponse(),
HttpWebResponse)

If myResponse.StatusCode = HttpStatusCode.OK Then
'Obtain a 'Stream' object associated with the response object.
Dim ReceiveStream As Stream = myResponse.GetResponseStream()
Dim encode As Encoding =
System.Text.Encoding.GetEncoding("utf-8")

'Pipe the stream to a higher level stream reader with the
required encoding format.
Dim readStream As StreamReader = New StreamReader(ReceiveStream,
encode)

'Read result
Dim Result As String = readStream.ReadLine()

'For testing purposes
Response.Write(Result)
Response.End()
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top