PayPal服务器集成不会通过Fetch Body参数传递数据

发布于 2025-01-21 08:15:40 字数 1111 浏览 1 评论 0原文

我正在关注PayPal的服务器集成演示: https://develper..paypaler.paypal.com/dempal.com/demo/demo/checkeckout/checkout/checkout/w./pattern/服务器

以下代码似乎不是通过“正文”参数传递数据:

      createOrder: function(data, actions) {
            return fetch('/paypal_api', {
                method: 'post',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({name:"sammy"}),
            }).then(function(res) {
                return res.json();
            }).then(function(orderData) {
                return orderData.id;
            });
        },

但是,我能够传递URL中的参数。例如:

返回fetch('/paypal_api/< some_variable>/',{

这样我就可以工作了,但是很难像预期的是邮政方法一样工作。这是我的python Server代码中的片段: class class class class CreateOrder(webapp2.requesthandler): def get feet(self):

    print self.request.params

...且打印语句什么都没有返回(Unicodemultict([]))。

我99%的人肯定我缺少一些明显的东西,因为Google没有帮助我! :)

I'm following PayPal's server integration demo:
https://developer.paypal.com/demo/checkout/#/pattern/server

The following code does not appear to be passing data via the "body" parameter:

      createOrder: function(data, actions) {
            return fetch('/paypal_api', {
                method: 'post',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({name:"sammy"}),
            }).then(function(res) {
                return res.json();
            }).then(function(orderData) {
                return orderData.id;
            });
        },

I am, however, able to pass parameters within the URL. For example:

return fetch('/paypal_api/<some_variable>/', {

So I can get this working but am bugged that the POST method does not appear to be working as expected. Here's a snippet from my python server code:

class createOrder(webapp2.RequestHandler):
def get(self):

    print self.request.params

... and the print statement returns nothing (UnicodeMultiDict([])).

I'm 99% certain that I'm missing something obvious since google is not helping me! :)

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

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

发布评论

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

评论(1

始于初秋 2025-01-28 08:15:40

将请求主体解析为JSON

import json

jsonstring = self.request.body
jsonobject = json.loads(jsonstring)

Parse the request body as JSON

import json

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