HttpWebRequest 是否自动发送 200 OK?

发布于 2024-08-10 08:42:41 字数 943 浏览 2 评论 0原文

背景:我正在实施 Paypal IPN 处理程序。

这篇关于 Paypal 的精彩 文章 指出我需要发送 200 OK阅读回复后返回 Paypal。

IPN 请求的处理如下:

//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();

根据以下内容(来自文章),代码(我猜)应该向 Paypal 发送 200 OK:

PayPal 将响应 VERIFIED 或 INVALID。收到此响应后,请务必发送 200 OK,以防止 PayPal 再次尝试发送 IPN

我没有看到任何明确的 HTTP 响应被发送为“200 OK”。

使用的HttpWebRequest是否自动发送200 OK?

如果是,那是在什么时候发生?

如果没有,如何使用 HttpWebRequest 发送 200 OK 响应?使用 HttpWebRequest 或套接字更容易做到这一点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

并安 2024-08-17 08:42:41

对于您真正要问的问题,简短的回答是肯定的,如果您的页面执行成功,ASP.NET 将发回 200。您所指的文章中的要点是您向 Paypal 发送请求以响应其向您发送的请求,因此发送 200 与 HttpWebRequest 对象无关,正如有人已经指出的那样。

因此,在本文中,如果您想将 200 发送回 Paypal,一旦页面成功执行,ASP.NET 就会自动执行此操作。

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.

七颜 2024-08-17 08:42:41

获得答案的最简单方法是使用 Wireshark 并查看到底来回发送了什么。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文