Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does HttpWebRequest send 200 OK automatically?

Tags:

c#

http

paypal

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?

like image 883
Marek Avatar asked Nov 08 '09 15:11

Marek


People also ask

How do I send a WebRequest to the server?

Send the request to the server by calling WebRequest.GetResponse. This method returns an object containing the server's response. The returned WebResponse object's type is determined by the scheme of the request's URI.

How many HTTP requests do I need to see?

In general, you want to see 200 requests. They are good! Let's talk about how the HTTP protocol works. At its very foundation, the Internet is made up of two core things: clients and servers. Any time you click on your browser, you are accessing the Internet through a web client. It may be Chrome, Firefox, Safari or Internet Explorer.

What is the meaning of the HTTP status 200?

The HTTP Status 200 (OK) status code indicates that the request has been processed successfully on server. The response payload depends on HTTP method which was selected for request. HTTP Status 200 – Response Payload

How do I use invoke-WebRequest with a stateful Web service?

This example shows how to use the Invoke-WebRequest cmdlet with a stateful web service. The first call to Invoke-WebRequest sends a sign-in request. The command specifies a value of "Session" for the value of the -SessionVariable parameter, and saves the result in the $LoginResponse variable.


1 Answers

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.

like image 149
Deeksy Avatar answered Sep 19 '22 20:09

Deeksy