【问题标题】:How to send json data in post-request to url in javascript如何在后请求中将json数据发送到javascript中的url
【发布时间】:2020-11-02 01:01:01
【问题描述】:

我想发送这样的数据

{"update_id":121631120,"message":{"message_id":1,"from":{"id":"TGID","is_bot":false,"first_name":"ELBARON @LxEEE","username":"USERNAME","language_code":"en"},"chat":{"id":"TGID","first_name":"ELBARON @LxEEE","username":"USERNAME","type":"private"},"date":1594553383,"text":"TEXT"}}

到这个网址

http://hfkm.ga/market/usersbothf/491856302/suc.php

使用 javascript,但我找不到任何帮助。

【问题讨论】:

标签: javascript json


【解决方案1】:

Axios 可用于发送 HTTP 请求,例如 fetch api。安装 axios 使用:npm install axios(假设安装了 nodejs)

您可以使用 CDN:<script src="https://unpkg.com/axios/dist/axios.min.js"></script>(将其粘贴到您的 index.html 中)

axios({
    method: 'post',
    url: '/login',
    data: {
        update_id: 121631120,
        message: {
            message_id: 1,
            from: {like so...}
        }
    }
})
.then((response) => {
        console.log(response);
    }, (error) => {
        console.log(error);
    }

更多详情:https://blog.logrocket.com/how-to-make-http-requests-like-a-pro-with-axios/

【讨论】:

  • 我不想使用 npm 只是我需要做这个网站做的事情reqbin.com 使用 js
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-16
  • 2016-09-29
  • 1970-01-01
  • 1970-01-01
  • 2021-02-11
相关资源
最近更新 更多