By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,180 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

Anyone using PayPal IPN with .NET?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

There is a free pay pal control from componentone in the vb.net and
the asp.net resource kits.

http://msdn.microsoft.com/asp.net/asprk/default.aspx
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx
Ken
---------------------
"Greg" <no****@nospam.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.