【问题标题】:Accessing 3rd party API from wix从 wix 访问 3rd 方 API
【发布时间】:2018-07-31 19:11:14
【问题描述】:

我正在尝试与第 3 方 API 进行通信。我用python编写了API。我想使用用户表单和文本框从 Wix 网页更新数据库中的名称列。数据库更新和所有端点都使用邮递员进行响应测试。我认为问题在于我在 Wix 端的 JavaScript。

我在以下位置对 Wix 示例中的 JavaScript 进行了建模: https://support.wix.com/en/article/calling-server-side-code-from-the-front-end-with-web-modules

我有一个名为 placeOrder 的后端模块存储在 orderplaced.jsw 中,它应该将变量“名称”发布到 api。

import { fetch } from 'wix-fetch';
// wix-fetch is the API we provide to make https calls in the backend

export function placeOrder(name) {
 return fetch("https://reliableeparts.pythonanywhere.com/user", {
        method: 'post',
        name: JSON.stringify({ name })

    }).then(function (response) {
 if (response.status >= 200 && response.status < 300){
            console.log(JSON.stringify({ name }))
 return response.text();}

    console.log(Error(response.statusText))



 return Error(response.statusText);}

    );
}

前端模块等待按钮单击并将文本框存储在名称变量中。

{
import {placeOrder} from 'backend/orderplaced.jsw';

export function button1_click(event, $w) {
     placeOrder(
         $w("#input1").value)

         .then(function() {
            console.log("Form submitted to backend.");
        }
     );
}
}

输出: 2 代码似乎到达了后端。我相信问题出在我的 placeOrder 函数上,因为我对 JavaScript 不是很熟悉。

【问题讨论】:

    标签: javascript velo


    【解决方案1】:

    您的代码似乎合法。问题出在服务器上。当我尝试向该地址发送POST 请求时,我得到了500 Internal Server Error

    您可以查看此curl 并自行测试服务:

    curl -i -X POST -H "Content-Type:application/json" https://reliableeparts.pythonanywhere.com/user -d '{"name":"test123"}'
    

    您可能缺少服务器期望的正确对象结构或缺少正确的标头POST 服务器(或两者都...)

    确保您遵循此服务器允许的 API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 2014-11-12
      • 2021-07-28
      相关资源
      最近更新 更多