tags:

views:

200

answers:

2

Background: I am implementing Paypal IPN handler.

This great article on Paypal states that I am required to send a 200 OK back to Paypal after I read the response.

The processing of IPN request is as follows:

//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), 
                         System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();

StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd(); //returns VERIFIED
streamIn.Close();

According to the following (from the article), the code (I guess) is supposed to send a 200 OK back to Paypal:

PayPal will respond with either VERIFIED or INVALID. After you receive this response, be sure to send 200 OK to prevent additional attempts from PayPal to send an IPN

I do not see any explicit HTTP response being sent as "200 OK".

Does the used HttpWebRequest send a 200 OK automatically?

If yes, at which point does that occur?

If not, how can one send 200 OK response using HttpWebRequest? Is it easier doing that using HttpWebRequest or sockets?

A: 

The easiest way to get the answer is to use Wireshark and see what exactly is getting sent back and forth.

Myles
+3  A: 

The short answer to the question you're really asking is yes, ASP.NET will send back a 200 if your page executes successfully. The point in the article that you are referring to is about you sending a request to Paypal in response to it's request to you, so sending 200 has nothing to do with the HttpWebRequest object as someone has already pointed out.

So, in the case of this article, if you want to send back 200 to Paypal, ASP.NET will do so automatically once the page has been successfully executed.

Deeksy
Thanks so much! It now makes sense to me. The "after you receive VERIFIED, send 200 OK" part was confusing me into thinking I should send it back to where the VERIFIED came from.
Marek