原料处理HTTP请求的内容 [英] Process raw HTTP request content

查看:126
本文介绍了原料处理HTTP请求的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做ASP.NET中的电子商务解决方案,它使用贝宝的网站付款标准服务。再加上,我使用他们提供的服务(付款数据传输),一个用户后发送回您的订单信息有完成付款。我需要做的最后一件事就是从他们解析POST请求,并坚持它的信息。 HTTP请求的内容就是以这种形式:

I am doing an e-commerce solution in ASP.NET which uses PayPal's Website Payments Standard service. Together with that I use a service they offer (Payment Data Transfer) that sends you back order information after a user has completed a payment. The final thing I need to do is to parse the POST request from them and persist the info in it. The HTTP request's content is in this form :


  第一次的 NAME = +简多伊

  最后一个
的名称=史密斯

  支付的状态=已完成

  付款人
的电子邮件= janedoesmith%40hotmail.com

  支付的 =总额3.99

  三菱商事
的货币= USD

  定制=表示正的+采购+ + +的罕见+书+绿色+鸡蛋+%26 +火腿

SUCCESS
firstname=Jane+Doe
last
name=Smith
paymentstatus=Completed
payer
email=janedoesmith%40hotmail.com
paymentgross=3.99
mc
currency=USD
custom=For+the+purchase+of+the+rare+book+Green+Eggs+%26+Ham

基本上我想分析该信息,并做一些有意义的事情,比如通过电子邮件发送或保存在数据库中。我的问题是什么是做解析ASP.NET中的原始HTTP数据是正确的做法,而不是如何解析本身就完成了。

Basically I want to parse this information and do something meaningful, like send it through e-mail or save it in DB. My question is what is the right approach to do parsing raw HTTP data in ASP.NET, not how the parsing itself is done.

推荐答案

这样的事情摆在你的onload事件。

Something like this placed in your onload event.

if (Request.RequestType == "POST")
{
    using (StreamReader sr = new StreamReader(Request.InputStream))
    {
        if (sr.ReadLine() == "SUCCESS")
        {
            /* Do your parsing here */
        }
    }
}

你要知道,他们可能要应对一些特殊的排序。(也就是说,不是完整的网页),所以你可能会做这样的事情,你就大功告成了解析后,

Mind you that they might want some special sort of response to (ie; not your full webpage), so you might do something like this after you're done parsing.

Response.Clear();
Response.ContentType = "text/plain";
Response.Write("Thanks!");
Response.End();

更新:这应该在通用处理程序(.ashx的)文件来完成,以避免从页面模式的开销很大。请查看约.ashx的文件的详细信息这篇文章

这篇关于原料处理HTTP请求的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆