472,358 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

webRequest object and PayPal

Hi,

I'm trying to use PayPal and its Instant Payment Notification. In short,
when a payment is made, PayPal send a post to my server and I post it back to
PayPal.

I'm using WebRequest to do this. I receive the PayPal post, but I can't post
it back. It's always giving me a Time out.

Here's my code:

// Setup Web request
objRequest = System.Net.WebRequest.Create(url);
objRequest.Timeout = timeoutSeconds * 1000;
objRequest.ContentType="application/x-www-form-urlencoded";
objRequest.Method = "POST";
// Create a copy of the http post received
// to post it back to paypal
NameValueCollection form = new NameValueCollection(Request.Form);
string hdrs = "";
foreach ( string var in form )
{
if (form[var] != null)
objRequest.Headers.Add(var,form[var]);
}
// Adds the Paypal validation field to the request
objRequest.Headers.Add("cmd","_notify-validate");

// Retrieve data from request
objResponse = objRequest.GetResponse();

....Then, nothing happens here and I receive a timeout webException.

I'm using this in other class where it's working really well. Also, I made a
HTML form to test the post from my server and it's working too. The PayPal
url exists and I don't understand why I can't reach it via webRequest.

Any idea?

Thanks,

Stephane

Nov 19 '05 #1
3 2713

"Stephane" <St******@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
Hi,

I'm trying to use PayPal and its Instant Payment Notification. In short,
when a payment is made, PayPal send a post to my server and I post it back to PayPal.

I'm using WebRequest to do this. I receive the PayPal post, but I can't post it back. It's always giving me a Time out.

Here's my code:

// Setup Web request
objRequest = System.Net.WebRequest.Create(url);
objRequest.Timeout = timeoutSeconds * 1000;
objRequest.ContentType="application/x-www-form-urlencoded";
objRequest.Method = "POST";
// Create a copy of the http post received
// to post it back to paypal
NameValueCollection form = new NameValueCollection(Request.Form);
string hdrs = "";
foreach ( string var in form )
{
if (form[var] != null)
objRequest.Headers.Add(var,form[var]);
}
// Adds the Paypal validation field to the request
objRequest.Headers.Add("cmd","_notify-validate");

// Retrieve data from request
objResponse = objRequest.GetResponse();

...Then, nothing happens here and I receive a timeout webException.

I'm using this in other class where it's working really well. Also, I made a HTML form to test the post from my server and it's working too. The PayPal
url exists and I don't understand why I can't reach it via webRequest.

Any idea?

Thanks,

Stephane

When paypal post to your post page you only need to send back the date they
posted with the appended cmd info

Try something like this. Careful of screen wrap and you will need to add
your code to handle the response you get
I have use setting in my web config. you will have to replace those values
with your own values.
Dim stringPost, stringResult As String

Sub Page_Load(sender as object, e as EventArgs)
Dim mgWebRequest As HttpWebRequest
Dim mgWebResponse As HttpWebResponse
Dim mgStreamWriter As StreamWriter
Dim mgStreamReader As StreamReader
stringPost = Request.Form.tostring()
' Send Data to paypal with append
mgWebRequest
=CType(WebRequest.Create(ConfigurationSettings.App Settings("paypalURL")),Htt
pWebRequest)

if request.form.get("receiver_email") =
ConfigurationSettings.AppSettings("paypalrec") then
mgWebRequest.Method = "POST"
mgWebRequest.ContentLength = stringPost.Length + 21 'length plus
21 because &cmd=_notify-validate is 21 chars long
mgWebRequest.ContentType = "application/x-www-form-urlencoded"
mgStreamWriter = Nothing
mgStreamWriter = New StreamWriter(mgWebRequest.GetRequestStream())
stringPost = stringPost + "&cmd=_notify-validate"
mgStreamWriter.Write(stringPost)
mgStreamWriter.Close()
mgWebResponse = CType(mgWebRequest.GetResponse(),HttpWebResponse)
mgStreamReader = New StreamReader(mgWebResponse.GetResponseStream())
stringResult = mgStreamReader.ReadToEnd()
mgStreamReader.Close()
if instr(1,stringResult,"VERIFIED") > 0 then
if request.form.get("payment_status") = "Completed" then
'code to write to data base
else
'code to handle other responses
end if
else if instr(1,stringResult, "INVALID") > 0 then
'code to handle the INVALID response
else
'code to handle unknown response
End if
else
'code to handle unrequest paypal posts. do really need anything here
end if
end sub

Nov 19 '05 #2

"vMike" <Mi****************@noZorY.geZwaYrrenY.com> wrote in message
news:cp**********@ngspool-d02.news.aol.com...

"Stephane" <St******@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
Hi,

I'm trying to use PayPal and its Instant Payment Notification. In short,
when a payment is made, PayPal send a post to my server and I post it
back to


I forgot to mention. The code I provided is the a "listening page" that
paypal will post to. The way I test it is to do the following.
Create a page to post TO the listen page. Then create another page with the
following

<html>

<body>
VERIFIED
</body>
</html>

change the setting it the code I sent to so that the paypaly url is the page
with the Verified in it. Using your posting page, you can post a paypal
tranaction to the listening page. Good luck.

Mike
Nov 19 '05 #3
It works. Thanks!!

"vMike" wrote:

"Stephane" <St******@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
Hi,

I'm trying to use PayPal and its Instant Payment Notification. In short,
when a payment is made, PayPal send a post to my server and I post it back

to
PayPal.

I'm using WebRequest to do this. I receive the PayPal post, but I can't

post
it back. It's always giving me a Time out.

Here's my code:

// Setup Web request
objRequest = System.Net.WebRequest.Create(url);
objRequest.Timeout = timeoutSeconds * 1000;
objRequest.ContentType="application/x-www-form-urlencoded";
objRequest.Method = "POST";
// Create a copy of the http post received
// to post it back to paypal
NameValueCollection form = new NameValueCollection(Request.Form);
string hdrs = "";
foreach ( string var in form )
{
if (form[var] != null)
objRequest.Headers.Add(var,form[var]);
}
// Adds the Paypal validation field to the request
objRequest.Headers.Add("cmd","_notify-validate");

// Retrieve data from request
objResponse = objRequest.GetResponse();

...Then, nothing happens here and I receive a timeout webException.

I'm using this in other class where it's working really well. Also, I made

a
HTML form to test the post from my server and it's working too. The PayPal
url exists and I don't understand why I can't reach it via webRequest.

Any idea?

Thanks,

Stephane

When paypal post to your post page you only need to send back the date they
posted with the appended cmd info

Try something like this. Careful of screen wrap and you will need to add
your code to handle the response you get
I have use setting in my web config. you will have to replace those values
with your own values.
Dim stringPost, stringResult As String

Sub Page_Load(sender as object, e as EventArgs)
Dim mgWebRequest As HttpWebRequest
Dim mgWebResponse As HttpWebResponse
Dim mgStreamWriter As StreamWriter
Dim mgStreamReader As StreamReader
stringPost = Request.Form.tostring()
' Send Data to paypal with append
mgWebRequest
=CType(WebRequest.Create(ConfigurationSettings.App Settings("paypalURL")),Htt
pWebRequest)

if request.form.get("receiver_email") =
ConfigurationSettings.AppSettings("paypalrec") then
mgWebRequest.Method = "POST"
mgWebRequest.ContentLength = stringPost.Length + 21 'length plus
21 because &cmd=_notify-validate is 21 chars long
mgWebRequest.ContentType = "application/x-www-form-urlencoded"
mgStreamWriter = Nothing
mgStreamWriter = New StreamWriter(mgWebRequest.GetRequestStream())
stringPost = stringPost + "&cmd=_notify-validate"
mgStreamWriter.Write(stringPost)
mgStreamWriter.Close()
mgWebResponse = CType(mgWebRequest.GetResponse(),HttpWebResponse)
mgStreamReader = New StreamReader(mgWebResponse.GetResponseStream())
stringResult = mgStreamReader.ReadToEnd()
mgStreamReader.Close()
if instr(1,stringResult,"VERIFIED") > 0 then
if request.form.get("payment_status") = "Completed" then
'code to write to data base
else
'code to handle other responses
end if
else if instr(1,stringResult, "INVALID") > 0 then
'code to handle the INVALID response
else
'code to handle unknown response
End if
else
'code to handle unrequest paypal posts. do really need anything here
end if
end sub

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: exxos | last post by:
HI all, This has had me confuzzeled for a while now, I've read countless threads on such errors and it seems to be down to the way things are set out and loaded. Can anyone suggest why this...
3
by: Bob Powell [MVP] | last post by:
It's not often I ask questions but here goes... I am writing a site that does Instant Payment Notification processing through PayPal and I need to use HttpWebRequest to hit an HTTPS server at...
5
by: archana | last post by:
Hi all i am having application which is using asychronous web request. At a time i am processing 5 urls asynchronously. Application working properly for 5 asynchronous call. But sometimes CPU...
3
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to create a call to a web page to validate and register software. The code I'm using is: Private Sub OK_Click(ByVal sender As...
0
by: PayPal Security Measures! | last post by:
<P><A href="http://www.paypal.com/cgi-bin/webscr?cmd=_home" target=_blank><IMG src="https://www.paypal.com/en_US/i/logo/paypal_logo.gif" border=0></A</P> <TABLE cellSpacing=0 cellPadding=0...
0
by: micahel | last post by:
Please chat with me by cnbbiz2008@hotmail.com to get the price and more photos, we take supplier paypal as payment. please see the photo album below for our product list. trainers supplier...
0
by: Nicodemus | last post by:
Do You Belive? \ cheapbbc@sina.com wrote in news:aecf26b6-4c75-4d87-b09c-a7380875e0f3 @w34g2000prm.googlegroups.com:
0
by: micahel | last post by:
Please chat with me by cnbbiz2008@hotmail.com to get the price and more photos, we take supplier paypal as payment. please see the photo album below for our product list. trainers supplier...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.