Meteor - Iron Router - 无法正确解析urlencoded http请求

时间:2015-07-27 23:44:10

标签: meteor iron-router body-parser

我有一个服务器路由设置,接受来自外部服务(PayPal)的POST请求。我以前通过访问路由的this.request.body函数内的action来获取所有细节,但是在最近进行流星更新之后,请求正文不再被正确解析,并找出原因显然超出了我的技能水平。

我想我可以回滚更新以使所有内容再次运行,但我正在试图弄清楚发生了什么。

所以我的问题是:为什么请求正文没有被正确解析?因为我在这里一无所知,即使只是在大方向上点头也会非常感激。

我的路线如下:

  this.route('ipnPay', {
    path: '/ipn/pay',
    where: 'server',
    action: function() {
        var request = this.request;

        console.log(request.body);
        //do other stuff
     }
   });

用于打印出如下所示的响应:

I20150727-18:09:46.656(-4)? { payment_request_date: 'Mon Jul 27 15:09:12 PDT 2015',
I20150727-18:09:46.657(-4)?   'transaction[0].id_for_sender_txn': '9PB44643108585943',
I20150727-18:09:46.657(-4)?   'transaction[0].receiver': 'tom@example.com',
I20150727-18:09:46.657(-4)?   'transaction[0].is_primary_receiver': 'false',
I20150727-18:09:46.657(-4)?   'transaction[0].id': '2HH18284E5553225C',
I20150727-18:09:46.657(-4)?   'transaction[0].status': 'Completed',
I20150727-18:09:46.658(-4)?   'transaction[0].paymentType': 'PERSONAL',
I20150727-18:09:46.658(-4)?   'transaction[0].status_for_sender_txn': 'Completed',
I20150727-18:09:46.658(-4)?   'transaction[0].pending_reason': 'NONE',
I20150727-18:09:46.658(-4)?   'transaction[0].amount': 'USD 266.67' }

但是在进行更新之后,请求体正在被解析:

I20150727-18:32:35.812(-4)?    { payment_request_date: 'Mon Jul 27 15:32:22 PDT 2015',
I20150727-18:32:35.813(-4)?      transaction: 
I20150727-18:32:35.813(-4)?       { '0].id_for_sender_tx': '7WE57612VB713004Y',
I20150727-18:32:35.813(-4)?         '0].receive': 'tom@example.com',
I20150727-18:32:35.813(-4)?         '0].is_primary_receive': 'false',
I20150727-18:32:35.814(-4)?         '0].i': '8B180259507549243',
I20150727-18:32:35.814(-4)?         '0].statu': 'Completed',
I20150727-18:32:35.814(-4)?         '0].paymentTyp': 'PERSONAL',
I20150727-18:32:35.814(-4)?         '0].status_for_sender_tx': 'Completed',
I20150727-18:32:35.814(-4)?         '0].pending_reaso': 'NONE',
I20150727-18:32:35.814(-4)?         '0].amoun': 'USD 10.00' } }

因此,解析器现在尝试创建嵌套的transaction对象,而不是第一个示例中的平面数据结构。但关键值正在搞砸......例如,第一个[被丢弃,因为最后一个字符(statu而不是status,typ而不是type等)。

这里有什么想法吗?

我通过ngrok获得的实际实际请求的正文是:

payment_request_date=Mon+Jul+27+15%3A09%3A12+PDT+2015&return_url=http%3A//localhost%3A3000/events/mHsWRFFnQSiX7zyem&fees_payer=SENDER&ipn_notification_url=http%3A//fnfndr.ngrok.io/ipn/pay&sender_email=xyz%40example.com&verify_sign=AqIeeetyNLVMnJSHSYCajOvN1y05Ai91xec8RhhiuUk10kK0d-xTI6gp&test_ipn=1&transaction%5B0%5D.id_for_sender_txn=9PB44643108585943&transaction%5B0%5D.receiver=tom%40example.com&cancel_url=http%3A//localhost%3A3000/events/mHsWRFFnQSiX7zyem&transaction%5B0%5D.is_primary_receiver=false&pay_key=AP-12T24911F3500884N&action_type=PAY&transaction%5B0%5D.id=2HH18284E5553225C&transaction%5B0%5D.status=Completed&transaction%5B0%5D.paymentType=PERSONAL&preapproval_key=PA-33150539CY900002V&transaction%5B0%5D.status_for_sender_txn=Completed&transaction%5B0%5D.pending_reason=NONE&transaction_type=Adaptive+Payment+PAY&transaction%5B0%5D.amount=USD+266.67&status=COMPLETED&log_default_shipping_address_in_transaction=false&charset=windows-1252&notify_version=UNVERSIONED&reverse_all_parallel_payments_on_error=false

这些是我运行流星更新时更新的软件包:

bigdsk:inputmask             upgraded from 3.1.42 to 3.1.63
gadicohen:sitemaps           upgraded from 0.0.21 to 0.0.22
meteorhacks:kadira           upgraded from 2.21.0 to 2.22.1
meteorhacks:kadira-profiler  upgraded from 1.1.0 to 1.2.0
meteorhacks:npm              upgraded from 1.3.0 to 1.4.0
meteorhacks:subs-manager     upgraded from 1.4.0 to 1.5.2
momentjs:moment              upgraded from 2.9.0 to 2.10.5
nemo64:bootstrap             upgraded from 3.3.4_2 to 3.3.5_2
nemo64:bootstrap-data        upgraded from 3.3.4_1 to 3.3.5
nimble:restivus              upgraded from 0.6.6 to 0.8.1
simple:json-routes           added, version 1.0.3
summernote:standalone        upgraded from 0.6.7 to 0.6.13

1 个答案:

答案 0 :(得分:0)

此行为与这两个包有关:

nimble:restivus              upgraded from 0.6.6 to 0.8.1
simple:json-routes           added, version 1.0.3

我不完全理解如何或为什么,但它在某种程度上干扰了铁的方式:路由器通常会解析HTTP请求。

因此,如果您遇到同样的错误,可以降级或删除上面的包。