【问题标题】:How to feed the payload data with Post request inside the Node api?如何在 Node api 中使用 Post 请求提供有效负载数据?
【发布时间】:2021-08-13 13:48:38
【问题描述】:

我在 NodeJS express api 中调用另一个 api,请求有效负载使用具有 Post 请求类型的证书,但有效负载不接受。问题是,如何在 Node api 中使用 Post 请求提供有效负载数据?

【问题讨论】:

    标签: javascript node.js express


    【解决方案1】:

    只需使用逗号分隔的 URL 传递有效负载, 例子 : 等待 axios.post('http://localhost:4000/createUser', 数据 );

    数据将作为另一个 API 的负载

    【讨论】:

    • 感谢您的支持。这一步我没问题,payload 在另一个 API 中不接受,显示错误请求。
    【解决方案2】:

    这是 Axios 的示例

    const axios = require('axios');
    
            var dataToPost = {
              email: "your email",
              password: "your password"
            };
    
            let axiosConfiguration = {
              headers: {
                  'Content-Type': 'application/json;charset=UTF-8',
                  "Access-Control-Allow-Origin": "*",
              }
            };
    
            axios.post('endpoint or url', dataToPost, axiosConfiguration)
            .then((res) => {
              console.log("Response: ", res);
            })
            .catch((err) => {
              console.log("error: ", err);
            })
    

    【讨论】:

    猜你喜欢
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2021-12-31
    • 2013-04-17
    • 2019-11-01
    • 1970-01-01
    相关资源
    最近更新 更多